Hello. I’m trying to make a BillboardGui with a TextLabel that gets a IntValue inside of the player. Something is wrong with my function.
local player = game:GetService("Players")
local localplayer = game:GetService("Players").LocalPlayer
local textLabel = script.Parent
local value = localplayer.LotteryFolder.LotteryWins.Value
player.PlayerAdded:Connect(function(plr)
textLabel.Text = ("Lottery wins: ".. (plr.LotteryFolder.LotteryWins.Value))
end)
Pictures of explorer:
Adding a print function inside doesn’t print anything either.
Any and all help is very much appreciated.
Are there any errors? You said that you have tried to add a print statement. Where did you put the print statement? Did you put it in the event function? If it didn’t trigger, are you sure that the script isn’t disabled? Try putting another print statement at the start of the script.
Script isn’t disabled. No errors either. Neither the print inside the function and outside the function work.
Could it be because .PlayerAdded can’t run on LocalScripts?
No, PlayerAdded doesn’t work in a LocalScript. You should just be able to do localplayer.LotteryFolder to access the folder.
So the code would look like:
local players = game:GetService("Players")
local localplayer = players.LocalPlayer
local textLabel = script.Parent
local value = localplayer.LotteryFolder.LotteryWins.Value
textLabel.Text = "Lottery wins: " .. value
I would recommend moving the script to StarterPlayerScripts, assuming you want the object in the workspace to display a different value for each player (whatever their value is in their LotteryFolder.
Make sure to also change the textLabel to the actual path of the label, since the script would no longer be under the label.
Also I was mistaken, PlayerAdded only triggers in a LocalScript when a different player is added to the game but it ignores the player that is running the script.
Oh right. I forgot that whenever I want to change GUI text with a LocalScript the script cannot be parented to whatever textlabel/box i’m trying to set but instead putting it into StarterGui or StarterPlayerScripts will make it work. Thank you so much.