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

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

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)

3 comments

0

i will try to fix this even though im a beginner

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

0

What if he doesnt want a Cooldown?

1 answer

✓ Accepted answer

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)

2 comments

0

also i don't know why you have "plr.leaderstats.Coins.Value = 10"

0

for testing

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