Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the player added script not working?

This is the script that I made, its supposed to clone an existing textbutton and then change the text to the players name, I also have a list UI layout that makes it into a list. But.... Its not working. Please help give me an answer, there's nothing in the output.

game.Players.PlayerAdded:Connect(function(player)
local give = script.Parent.TextButton:Clone()
give.Text = player.Name
end)

4 comments

0

I honestly do not know

0

:C

0

well, it cloned the textbutton, but if you want to put it in the player screen you have to put it inside their PlayerGui Like this: give.Parent = player.PlayerGui. I think it has to be inside a ScreenGui object to be visible too.

0

Thanks!

1 answer

✓ Accepted answer

Fun fact, I also didn't know until recently but local scripts run after the local player joins. This means the script will run AFTER the player joins, thus meaning PlayerAdded won't fire for the local player. Just simple remove the PlayerAdded event, also use :GetService()

local player = game:GetService("Players").LocalPlayer
local give = script.Parent.TextButton:Clone()
give.Text = player.Name

2 comments

0

If you didn't know that you probably won't know this, but if you try to get the character by player.Character right at the start of the script it might return nil. The best approach is to do it like this: local char = player.Character or player.CharacterAdded:Wait(). This way, it will see if the player has the character and return it, if it doesn't, it yields until the character is added.

0

I already know that, thanks for sharing though.

This discussion is preserved as it was. New answers, comments, and votes are closed.