Gui score not working (simple fix?)

I want to create a score that changes a text on screen so far I have:

local player = game.Players.LocalPlayer
local score = player.PlayerGui.ScreenGui.ScoreFrame.TextLabel.Text

it is erroring with “attempt to index nil with ‘PlayerGui’” , I assume it means the player doesn’t exist. All help appreciated!

I’m pretty sure the problem is that the player is still not loaded in by the time the script loads…
Just to confirm that, where is your script located?

it is located in a model in the workspace and I have tried putting a wait before it

Local scripts don’t work in the workspace, try to place it on StarterPlayerScripts, maybe that works.

1 Like

It is with other scripts on when you touch something it changes your score by one, how would I make it so when the part is touched it tells the other script to change the text?

I’m not really good with scripting so I don’t know if I can help, but can you show the other script you mentioned

its a part.Touched:Connect(function(hit) type of script

I’d say the best approach to your goal is to make a local script and place that part.touched function on it, that way, you can add the “change score by one” thing in that function.

However, if you do not wish to do the part.touched function on a local script, I recommend looking into RemoteEvents.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.