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

How to extend function wait() if called twice or more?

Asked by
TechModel 118
3 years ago
Edited 3 years ago

I've been searching on the internet and I get unrelated stuff so I want clear answers hopefully. The problem is if the remote event was triggered twice, how would I reset the "wait(5)" again so until it the remote stops being called. Then it counts down to 5 until it ends.

1game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
2 
3    player.Time.Value = true
4        wait(5)
5    player.Time.Value = false
6end)
0
use a for loop with if statements and probably a debounce unless you are asking for something like delay(5,function() greatneil80 2647 — 3y

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
3 years ago

Not quite sure what you're asking, but I've come up with a script.

01-- Local Script (inside a tool!)
02local Tool = script.Parent
03local Player = game.Players.LocalPlayer
04 
05local RE = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent",10)
06Tool.Activated:Connect(function()
07    RE:FireServer()
08end)
09 
10--[[
11#################################################################################
12]]
13 
14-- Script
15local Players = {}
View all 52 lines...

This script logs every player that joins the game and adds your Time bool value to each player. The server side script then waits for a player to activate or click with the tool to change the Time.Value from false to true, as you had, then waits 5 seconds before changing it back to false.

I've made it ignore any other clicks made by a player. Thus stopping the click spam. I've also allow other players to change their Time bool values without locking up the system until the Clicked Value gets changed back to false.

Let me know if you need anything :)

Ad

Answer this question