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

Why can't I change something in PlayerGui?

I need to change the text of a TextLabel to the word "HI" when a part is touched. It won't work, though. The TextLabel is in a ScreenGui in StarterGui. This script is in a part in the Workspace. Can someone tell me what I'm doing wrong?

script.Parent.Touched:connect(function(hit)
	if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		script.Parent:Destroy()
		game.Player.LocalPlayer.PlayerGui.ScreenGui.Total.Text = "HI"
	end
end)

1 comment

0

Is it in a LocalScript?

1 answer

✓ Accepted answer

Use GetPlayerFromCharacter to get the person who touched the part's player

script.Parent.Touched:connect(function(hit)
	if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			player.PlayerGui.ScreenGui.Total.Text = "HI"
			script.Parent:Destroy()
		end
	end
end)

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