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

GUI open script doesn't work?

Asked by
lucas4114 607 Moderation Voter
9 years ago

So, I used this to make a GUI open by a part touch, but when I tested it in studio it worked, in game.. It worked when I touched it while I was alone in the server, but when I told someone to join the part didn't open to GUI for me, or the other person...!

debounce = false
GUIopen = script.Parent.Value

function onTouched(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr and debounce == false then
        if GUIopen.Value == false then
            debounce = true
            GUIopen.Value = true
            wait(0.1)   
            plr:WaitForChild("PlayerGui").TeleportMenu.Background.Visible = false
            debounce = false
        end
    end
end

script.Parent.Touched:connect(onTouched

Help please D:

0
Are there any errors? Do you ever disable GUIopen? AmericanStripes 610 — 9y
0
No errors, yeah I put a scipt in the "Close" button in the GUI thats ment to open, that makes the boolvalue of the GUIopen false when pressed... lucas4114 607 — 9y

1 answer

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
9 years ago

Ok I finally found out what your error was, The error was the use of Debounces, Here is the fixed Code:

debounce=false
function onTouched(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
wait(0.1)
if not debounce then
debounce=true
plr.PlayerGui.TeleportMenu.Background.Visible = false
end
debounce=false
end

script.Parent.Touched:connect(onTouched)

I edited it a bit, I changed the Postitions of the Debounces, If there are any errors just comment below.

Note: I had removed the BoolValue

0
Yeah, but then when a player steps on it, the GUI opens itself way too may times.... lucas4114 607 — 9y
0
Oh I see let me update it. woodengop 1134 — 9y
0
Why not just use the debounce conditional from the start of the function? That way you don't even have to go about the 'wait' statement and the compiler won't bother referencing plr each time debounce might be false DigitalVeer 1473 — 9y
Ad

Answer this question