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

How do i make my gui always open when i touch a part?

Asked by 4 years ago
Edited 4 years ago

Here is my script which opens a gui when i step on a part:

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        game.Players:GetPlayerFromCharacter(hit.Parent:FindFirstChild("Humanoid").Parent).PlayerGui.shop.Enabled = true
    end
end)

but when i press the exit button

script.Parent.MouseButton1Click:connect(function()
    script.Parent.Parent.Parent.Enabled = false
end)

then when i step on the part again the gui doesnt open, can anyone help?

(on the first script i didnt just skip a bunch of stuff its just cut off for some reason. just press view source code)

1 answer

Log in to vote
0
Answered by
EmK530 143
4 years ago
Edited 4 years ago

Assuming the part script is a ServerScript and the exit button is a LocalScript. If that is the case then this is the reason.

The first time when the GUI opens from the ServerScript, it works fine but why it won't do it a second time is because the GUI was closed from a LocalScript, and because of that the server still sees that the GUI is enabled even though it's not so it doesn't do anything.

My suggestion is to first disable the GUI and then enable it:

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        game.Players:GetPlayerFromCharacter(hit.Parent:FindFirstChild("Humanoid").Parent).PlayerGui.shop.Enabled = false
        game.Players:GetPlayerFromCharacter(hit.Parent:FindFirstChild("Humanoid").Parent).PlayerGui.shop.Enabled = true
    end
end)
Ad

Answer this question