✓ Accepted answer
This mistake is made a lot.
Making you changes in StarterGui won't work. StarterGui is not what you see! It is simply a holder or a container that you use to store guis.
When you join the game and each time your respawn, everything in StarterGui is cloned into PlayerGui. This is what you see. (You can only see stuff in StarterGui in studio for testing purposes. In-game, you view PlayerGui.)
So to solve your problem, we must make our changes in that specific player's PlayerGui. Each player has his or her own PlayerGui, so we must make sure we get the correct one.
The hit parameter will help us out. If a true player character touched the brick, then hit.Parent must be his or her Character object. Now that we have the character, we can get the Player.
We could make a search through Players service with FindFirstChild, but there's a better method. We can use GetPlayerFromCharacter. This method of the Players service will take the Character given in the parentheses and find its matching Player. It will then return that Player -- or nil if a valid Character was not given. In case it returns nil, an extra check must be made.
debounce = false
function onTouched(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr and debounce == false then
debounce = true
plr:WaitForChild("PlayerGui").ScreenGui.TextLabel.Visible = true
debounce = false
end
end
script.Parent.Touched:connect(onTouched)
2 comments
It appears I posted a bit slow, lol.
What does the debounce mean