game.Workspace.ChildAdded:connect(function(child) local h = child:WaitForChild("Humanoid") local Torso = h.Parent:FindFirstChild("Torso") if h then local Smoke = Instance.new("Smoke") h.WalkSpeed = 32 --Change for different Walkspeed on join Smoke.Parent = Torso Smoke.Color = Color3.new(209, 0, 255) Smoke.Opacity = 0 Smoke.RiseVelocity = 0 Smoke.Size = 0 end local StickyBombValue = Instance.new("IntValue") StickyBombValue.Parent = child StickyBombValue.Name = "StickyBombValue" local ImageLabel = game.StarterGui.ScreenGui:FindFirstChild("PlayerImage") ImageLabel.Parent = game.StarterGui.ScreenGui ImageLabel.Position = UDim2.new(0, 25, 0, 50) ImageLabel.Size = UDim2.new(0, 100, 0, 100) ImageLabel.Image = "rbxassetid://133293265" ImageLabel.BackgroundColor3 = Color3.new(207, 207, 207) end)
This is a script from my game that is intended to set everything up when a player joins. You can ignore everything until the image label part. For some reason, the ImageLabel just won't do anything. It won't change position, change size and it's invisible. However, if I take that block of script out of game.Workspace.ChildAdded:Connect(function(child) and just put it at the bottom of the script then it works fine. Any ideas as to why the ImageLabel won't work if its in a function?
Ok, so here are a few problems with your script - you don't use :ChildAdded
when you want to do something when a player joins - you use :PlayerAdded
, the second problem is that the contents inside of StarterGui get copied into the player when they join, so any modification made to anything inside of StarterGui after the player has joined WON'T modify the player's gui. The contents of StarterGui actually get copied inside of Player.PlayerGui (Player being whatever the player's name is), so a fix for that would be:
game.Players:PlayerAdded:connect(function(player) ~~~note the usage of PlayerAdded instead of ChildAdded local h = player.Character:WaitForChild("Humanoid") local Torso = h.Parent:FindFirstChild("Torso") if h then local Smoke = Instance.new("Smoke") h.WalkSpeed = 32 --Change for different Walkspeed on join Smoke.Parent = Torso Smoke.Color = Color3.new(209, 0, 255) Smoke.Opacity = 0 Smoke.RiseVelocity = 0 Smoke.Size = 0 end local StickyBombValue = Instance.new("IntValue") StickyBombValue.Parent = child StickyBombValue.Name = "StickyBombValue" local ImageLabel = player.PlayerGui.ScreenGui:FindFirstChild("PlayerImage") ImageLabel.Parent = game.StarterGui.ScreenGui ImageLabel.Position = UDim2.new(0, 25, 0, 50) ImageLabel.Size = UDim2.new(0, 100, 0, 100) ImageLabel.Image = "rbxassetid://133293265" ImageLabel.BackgroundColor3 = Color3.new(207, 207, 207) end)
Additional explanations - the reason the code works after you put the part with the image label after the ChildAdded event block is because that code runs when the server starts, before the player/child added event is fired, so the image label is modified inside of StarterGui before the player joins, thus the modified contents of StarterGui get copied into the PlayerGui of the player.
~~~if I made any mistakes please point them out in the comments, thanks!~~~