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

Touch-to-open gui script isnt working. Why does this happen?

Asked by 5 years ago
Edited 5 years ago

I made a shop gui and it works and all, but when i tried making the part that opens it when you touch it, it works only one time. After i close it and try to open the gui again, it does nothing. I have no idea why. this is the script of the part to open the gui:

debounce = false
script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr and debounce == false then
        debounce = true
        plr.leaderstats.Coins.Value = 10
        plr.PlayerGui.ScreenGui.Shopkeepa.Visible = true
        debounce = false
    end
end)
0
i will try to fix this even though im a beginner 3wdo 198 — 5y
0
You need to be waiting before enabling debounce. In between lines 7 and 8, wait(n) where n is how long you want the cool down to be User#24403 69 — 5y
0
What if he doesnt want a Cooldown? 1DoctorProctor1 0 — 5y

1 answer

Log in to vote
0
Answered by
Dleppyy 41
5 years ago
Edited 5 years ago

Put this in a server script as a child of the part you want the player to touch

script.Parent.Touched:Connect(function(hit)

local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

local Gui = Player.PlayerGui.ScreenGui.Shopkeepa

repeat wait() until game.Players:GetPlayerFromCharacter(hit.Parent)

while wait() do
    for i, v in pairs(game.Players:GetChildren()) do
        if (v.Character.Head.Position - script.Parent.Position).magnitude <= 5 then
        Gui.Visible = true
        else
       Gui.Visible = false
            end
        end
    end
end)
0
also i don't know why you have "plr.leaderstats.Coins.Value = 10" Dleppyy 41 — 5y
0
for testing AradIsHere 2 — 5y
Ad

Answer this question