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

Script that is supposed to make a GUI pop up if a block is touched doesn't work, why?

Reposted due to no answers being posted on my last post. So what this script is supposed to do is make a GUI pop up when a part is touched. It isn't working, why? Here is my script:

local Part = script.Parent

Part.Touched:connect(function(HIT)
 local H = HIT.Parent:FindFirstChild("Humanoid")
 if H then
  local Player = game.Players:GetPlayerFromCharacter(HIT.Parent)
  Player.PlayerGui.ScreenGui.Frame.Visible = true
 end
end)?

2 comments

0

Is there an error in the output?

0

Also, what script are you using?

1 answer

You can only alter the gui through a local script, and local scripts only run when inside something that is individual to the player, such as their PlayerGui.

To fix this, you can move it to a local script inside StarterGui and do something like this:

local Part = workspace.Button --change to directory of button
Part.Touched:Connect(function(hit)
	if hit.Parent == game.Players.LocalPlayer.Character then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true
	end
end)

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