Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)?
0
Is there an error in the output? Florian27 76 — 6y
0
Also, what script are you using? Florian27 76 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

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

Answer this question