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

How to Use Debounce With Multiple Players?

Asked by 6 years ago

Okay, so heres my problem. Currently I a using a debounce function and it works great except that it only works when the first player touches it and not for any other player afterward. I need this script to work when any player touches it, but I only need it to happen once. Any help with this would be greatly appreciated. Here is the script:

local part = game.Workspace["Floor Brick Shop"] --gets the part
walkedon = 0

part.Script.Opens.OnServerEvent:Connect(function(player,HIT) --you mistaken Open as Touched in your script
    if walkedon == 0 then

        walkedon = 1   

 local h = HIT.Parent:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(HIT.Parent)
-- do this every time a new character for each player is created


local PlayerGuiServer = game.ServerStorage.Store -- Replace 'nil' with the location of your folder

for _, screenGui in pairs(PlayerGuiServer:GetChildren()) do
    screenGui:Clone().Parent = player.PlayerGui

end
    if h then
        player.PlayerGui.ShopGui.ShopFrame.Visible = true

    end
walkedon = 1
wait(0.9)
     end
end)
0
Also if I set the last walkedon(which is the debounce function) to 0 at the end of the script it doesn't work and just keeps running it over and over CrazyRoblots 13 — 6y
1
You should be doing this on a local script its only making a gui visible. User#5423 17 — 6y
0
But that is the server script. I have filtering enabled on. The way I understand it is that I need to have both a local and a serve script when filtering enabled is on CrazyRoblots 13 — 6y
0
It is common for gui to be stored in rep storage and cloned when needed to the player. You would then use a remote event to process any of the users requests on the server so that they replicate. Gui effects / setup can all be safely done on the client side since they should only read data not change the game itself. User#5423 17 — 6y
0
Run this on the client, like kingdom5 said Validark 1580 — 6y

Answer this question