Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is the player added script not working?

Asked by 3 years ago

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)
0
I honestly do not know jhjryoutube 29 — 3y
0
:C Golden_Tyler115 54 — 3y
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. Dfzoz 489 — 3y
0
Thanks! Golden_Tyler115 54 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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
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. Dfzoz 489 — 3y
0
I already know that, thanks for sharing though. nekosiwifi 398 — 3y
Ad

Answer this question