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)
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)