Cloned Gui Frame from ReplicatedStorage is parented in StarterGui, but still not visible - roblox

I am trying to clone a frame from ReplicatedStorage and parent it to another frame in StarterGui. I expect to see the text in the frame, but cannot. When I manually duplicate the frame in ReplicatedStorage in the editor and drag it to the frame in StarterGui, it works fine, and I see can see the text. There are no errors or warnings. When I run the script and the updateDisplay function is called, I can see and move the edges of the frames from ReplicatedStorage but not the text.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local updateResourceDisplay = ReplicatedStorage:WaitForChild("UpdateResourceDisplay")
local function updateDisplay(resources)
for key, value in pairs(resources) do
local newResource = ReplicatedStorage.ResourceTemplate:Clone()
newResource.Parent = StarterGui.ScreenGui.LeftFrame.Frame
end
end
updateResourceDisplay.OnClientEvent:Connect(updateDisplay)

Turns out that StarterGui is only for the... start. If you want to change the player's gui at runtime, that's done with PlayerGui not StarterGui. Changing the second line to the following code and replacing the reference from StarterGui to PlayerGui worked:
local PlayerGui = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')

Related

How to make object following player smooth

I use MoveTo for following the position and change the CFrame for rotation but it looks supper jaggy. I think the problem is that the code is on the server-side and not on the client-side since I want other players to be able to see the object following the player
Try using weldConstrain. You can create it by code and connect 2 parts to it. The parts are going to stay at the same relative position from each other. Here is a link for the API reference about the subject: https://developer.roblox.com/en-us/api-reference/class/WeldConstraint
Here is an example code that adds a part at the top of a player's head when it joins the game:
local Players = game:GetService('Players') -- get's the players service
local function OnPlayerAdded(player)
local PlayerCharacter = player.Character
-- waits until the player's character loads
while PlayerCharacter == nil do
wait(1)
PlayerCharacter = player.Character
end
-- Get's the player's model in workspace
local PlayerModel = workspace:WaitForChild(PlayerCharacter.Name)
-- Get's the player's head inside it's model
local PlayerHead = PlayerModel:WaitForChild('Head')
-- Write the path to the part you want to follow the player, bellow
local FollowPartOriginal = workspace:WaitForChild('Part')
-- If you want to clone the part, so more players can be followed by it,
-- don't delete the line below, if you want only 1 part, delete the line below.
local FollowPart = FollowPartOriginal:Clone()
-- set's the part position on top of the player's head, with an offset
FollowPart.Position = PlayerHead.CFrame.p + Vector3.new(0,2,0)
FollowPart.Parent = workspace
-- creates a weldconstrain
local WeldConstraint = Instance.new('WeldConstraint')
-- connect's the weld to the player's head and the other part
WeldConstraint.Part0 = PlayerHead
WeldConstraint.Part1 = FollowPart
WeldConstraint.Parent = PlayerHead
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Place this code in a script(not a local script).
If you use the function separately, don't forget to put the player parameter. The parameter needs to contain the player Instance(ex: game.Players.PlayerName)
To change the part position, use the offset in this line of the code:
FollowPart.Position = PlayerHead.CFrame.p + Vector3.new(write offset here)
If you want the part the stop following the player, make a script to delete the part, or the weld constrain(child of the player's head)

Roblox - attempt to call a nil value

When trying to create a code, that on FireServer with Specific Player chosen a GUI would've been cloned into their PlayerGui, But instead I get a nil value.
Code:
local Blinder = game.ReplicatedStorage.RCD.Blind
Blinder.OnServerEvent:Connect(function(player, PlayerToBlind)
if not player:IsInGroup(7465879) then return false end;
script.BL:Clone().Parent = PlayerToBlind:WaitForChild("PlayerGui")
print("Done")
end)
Basically what I try to reach is if my Admin Panel Remoteevent is fired, and a Target has been chosen, the Targeted Player will become a Cloned GUI into their PlayerGui
Any fix on this error?
The error message itself is telling you that you are calling a function that doesn't exist. This issue is caused by an object not being the type you expect.
Unfortunately, the message is pointing at a line that has a few function calls, so it's difficult to say what is causing the exact error. Either script.BL isn't an object with a Clone() function, or PlayerToBlind isn't an object with a WaitForChild() function.
If you can break the operations into a few different lines and add safety checks along the way, you can guarantee that your code is safe and being called properly.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Blinder = ReplicatedStorage.RCD.Blind
local BL = script.BL
Blinder.OnServerEvent:Connect(function(player, PlayerToBlind)
-- check that the person calling Blinder:FireServer actually provided a PlayerToBlind
assert(type(PlayerToBind) == "string", "Blinder expects PlayerToBind to be the name of a player")
-- escape if the player is not in the appropriate group
if not player:IsInGroup(7465879) then
return
end
-- find the Player object based on the name provided from PlayerToBlind
local blindedPlayer = Players:FindFirstChild(PlayerToBlind)
if not blindedPlayer then
warn("Could not find player named : ", PlayerToBlind)
return
end
-- create a blinding UI on the other player
local targetGui = blindedPlayer:WaitForChild("PlayerGui")
local newBL = BL:Clone()
newBL.Parent = targetGui
print("Done")
end)
By adding asserts into your code, it won't stop your code from breaking, in fact it will force your code to break faster and in expected ways.
The issue has been fixed,
I have been setting up the LocalScript wrong.
(I grabbed the Text from a TextButton, Instead of the TextBox)

Animation Script not working in ReplicatedStorager

I have a a Gun model that shows up on my screen using the code from https://www.youtube.com/watch?v=VDYtZxnz7FI&t=25s youtube video. But when I try to add animations to it the animations dont work. What I think is happening is that the script isnt loading in because its in Replicated Storage. I Know this because I tested a simple print command and it worked when the script was in the workspace but not in replicated storage. I cant move the model to the workspace because the code depends on it being in replicated storage. If anyone could help me that would be much abliged. Thank You! Im not new to the Roblox scene but im just starting as a Scripter, Either then a mesh modeler.[Picture of Explorer][1]
Here Is the code that puts the viewmodel on my screen
local cam = workspace.CurrentCamera
local run = game:GetService("RunService")
local reps = game:GetService("ReplicatedStorage")
local model = reps:WaitForChild("Henry Rifle"):Clone()
for i,v in pairs (model:GetChildren()) do
if v:IsA("BasePart") then
if v ~= model.PrimaryPart then
local weld = Instance.new("Weld")
weld.Part0 = model.PrimaryPart
weld.Part1 = v
weld.C0 = model.PrimaryPart.CFrame:inverse()
weld.C1 = v.CFrame:inverse()
weld.Name = v.Name
weld.Parent = model.PrimaryPart
end
end
end
model.Parent = cam
run.RenderStepped:connect(function()
model:SetPrimaryPartCFrame(cam.CFrame *CFrame.new(0,-1.5,1.5))
end)
Here is the simple code that start the animation when the game starts
(Used for Testing)
local player = game.Players.LocalPlayer
local controller = script.Parent.Humanoid
local inspect = controller:LoadAnimation(script.Parent.Inspect)
inspect.Looped = true
inspect:Play()
I'm pretty sure your script doesn't work because Roblox forces Filtering Enabled now.
Filtering Enabled (FE)
Difference with non FE and FE games
With FE, Changes made by the Client/Roblox Player is sent to the server, but the server will never replicate the changes made by the Client to others Clients in the same game server.
That video was made when FE was still an option. Roblox forces FE now, this is why your script doesn't work.
Only way for Client to replicate with others Clients, You must use Remotes.
Roblox wiki explains better than me FE and Remotes, so check it out: http://roblox.wikia.com/wiki/Replication_filtering

MIT-Scratch : Sequential cloning without delay

I am just starting to play with this as an educational tool for a youngster and encounter strange behavior whilst attempting to clone sprites.
I setup a global variable for position x,y in sprite_1 and clone a sprite_2 object. This object immediately copies the global x,y to local x,y and exits. Later sprite_2 renders using the stored local x,y.
sprite_1:
sprite_2:
I expect the four sprites to clone diagonally up/right on the screen according to this small reproduce-able example. Instead I appear to get four sprite_2 objects all on top of each other:
If I add a delay of 1 second onto the end of the clone(x,y) function however all is well:
As all four sprite_2 objects appear to be where the last clone was placed, I have a suspicion that the clones are not created immediately but instead created as a batch all at once, at some time and therefore are all taking the last coordinates from the globals _clone_enemy_x/y.
Is this the case? is there are way to circumvent this behavior or what is the solution?
I have 2 possible solutions to this problem:
Go to the "define clone()()" block, right click it, open up the advanced dropdown, and tick "run without screen refresh".
Get rid of the custom block all together, but use the original source for that block in the actual code.
I hope this helps!

unexpected frame appears onto another frame after an event

I'm using a character application. In the first page, there is a frame f-selection where the search fields are entered. When I search for something and open some other frames in that search, then I press F10 which is for opening another frame, the new frame opens but f-selection also appears on it. I'm suspecting this code makes it pop up again:
else assign ll-lgst-key1:SENSITIVE in frame f-selection = TRUE
ll-lgst-key2:SENSITIVE in frame f-selection = FALSE
because when I comment these lines, the frame doesn't pop up. But then I can't use these fields at the first frame where I should, too. I don't know why this code is called again; but is there anything else I can do to fix this issue? I tried to write hide frame f-selection everywhere possible but it doesn't work.
That snippet of code is making "key1" of your frame sensitive. In order to be sensitive it needs to pop up...
So the issue is why is that block of code executing? You say "I don't know why this code is called again". Neither will anyone else because you have shared such a tiny little bit of the overall code. Apparently the flow of control is taking you through that block so you should work on understanding why that is. You might try using the debugger to step through the code execution or you could insert some old fashioned MESSAGE statements to get to the bottom of it.
If you want to kludge around the problem you could wrap that bit of code in conditional logic. Define and set a variable that determines the desired state of the f-selection frame and use that to control the sensitivity logic:
define variable f-shouldBeVisible as logical no-undo.
if .... then
f-shouldBeVisible = yes.
else
f-shouldBeVisible = no.
...
else
do:
if f-shouldBeVisible then
assign ll-lgst-key1:SENSITIVE in frame f-selection = TRUE
ll-lgst-key2:SENSITIVE in frame f-selection = FALSE
.
end.
Of course that looks kind of silly -- but it is just an example with grossly over-simplified logic.
OTOH if you know enough to set the variable you ought to be able to figure out why the ELSE branch is executing. But maybe it is a useful first step.