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

script wont update textlabel in localplayer.playergui but it does in startergui why?

Hello, I am trying to make game where you find endings and it counts up how many you have on an gui. I put in script on part touched it goes to playergui and updates text there from 0/13 found to 1/13 found. It worked in startergui it updated the text but when i put it to playergui it doesnt do nothing.

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("HumanoidRootPart") then
		script.Parent.Parent.Parent.Parent.Players.LocalPlayer.PlayerGui.EndingGui.Menu.Easyendings.oo13.Text = "1/13 found"
	end
end)

1 answer

✓ Accepted answer

LocalPlayer can NOT be accessed via server-side.

It is the LocalPlayer of the client but since a script is not a client script, it obviously doesn't work

You can use GetPlayerFromCharacter()

script.Parent.Touched:Connect(function(part)
    if part.Parent:FindFirstChild("HumanoidRootPart") then     
	local player = game.Players:GetPlayerFromCharacter(part.Parent) -- It gets a model and gets the player of the character
	if player then 
		player.PlayerGui.Ending.Text = '1/13 found' -- I think you mean text
	end
	
    end
end)

It is really unnecessary to go like script.Parent until it reaches game and do .Players.

You can easily use game.Players

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