So I have this script here which basically when Touched, will turn red, clone a random map from ServerStorage to a folder in the Workspace, and teleport the player to a part called "Part3". The problem is that only one person can press this button and be teleported to a map; the rest of the players have to wait until he completes the map or the timer (nuke) runs out. How could I use a delay function or something else to allow multiple people pressing the button and track the players on a table?
(A delay of about 5 seconds would probably help a lot considering players will not press a button at the exact same time)
Here is the full script:
local Teleport = "Part3" local part = script.Parent part.BrickColor = BrickColor.new("Bright green") local playertable = {} function Touch(hit) if hit and hit.Parent and hit.Parent:IsA("Model") then print("OK") else return end if part.BrickColor ~= BrickColor.new("Bright green") then return end part.BrickColor = BrickColor.new("Bright red") script.Parent.BillboardGui.Enabled = false local mapstorage = game.Workspace:WaitForChild('nukeeasy') mapstorage:ClearAllChildren() local mapsinserverstorage = game:GetService('ServerStorage').NukeMaps.Easy:GetChildren() local chosenmap = mapsinserverstorage[math.random(1, #mapsinserverstorage)] chosenmap = chosenmap:Clone() chosenmap.Parent = mapstorage print(hit) print(hit.Parent) print(hit.Parent:IsA("Model")) print(chosenmap) print(chosenmap:findFirstChild(Teleport)) this = true if this == true then wait(2) if hit and hit.Parent and hit.Parent:IsA("Model") and chosenmap and chosenmap:findFirstChild(Teleport) then this = false hit.Parent:moveTo(chosenmap:findFirstChild(Teleport).Position) wait(1) this = true end if chosenmap.Name == "WrWaRo" then script.Parent.WrWaRo.Disabled = false end if chosenmap.Name == "SiSe" then script.Parent.SiSe.Disabled = false end if chosenmap.Name == "SuSo" then script.Parent.SuSo.Disabled = false end end end part.Touched:Connect(Touch)
Do not mind the if-then checks for chosenmap.Name, that is just another system.
Thank you!
What you will need is known as a debounce. A debounce basically prevents a block of code from running over and over again. Have a variable set up for the debounce and in the code have it check if that variable is true, if true then set it to false. Then you would need to set it back to true when you need to. I'll send an example of a really basic debounce below:
local debounce = true local function PrintStuff() if debounce then debounce = false print("passed debounce") end end PrintStuff() PrintStuff() wait(3) debounce = true PrintStuff()
As you can tell, it would print "passed debounce" once and then wait 3 seconds, set the variable to true and print it again.