Depending on what the countdown is used for, I don’t really see the issue with handling it on the client, if it isn’t going to cause immense harm by it being skipped than accounting for exploits in that regard isn’t entirely necessary.
As for handling the countdown on the server, you should be using RemoteFunctions as opposed to RemoteEvents so that the client can receive a returned value upon the countdowns completion that essentially tells it to proceed with whatever code was waiting.
Okay, I’m going to try to do it in detail. So I have a local script which when you press a key on your keyboard call the RemoteEvent, currently the countdown is on the localscript so an exploit could easily bypass it and I would like to set the countdown on the server script for completely stop the exploiter
Alright, well, to put it simply, you could track the time a players countdown has through a variable in the RemoteFunction “processing function”, or you could store it in an external value somewhere and view it’s value at any time.
script.Function.OnServerInvoke = function(Time)
repeat wait(1) Time = Time - 1 until Time <= 0
return
end)
“Time” in this scenario, before the repeat loop, would be the total time a players countdown has. You could transfer this into a Number/IntValue or you could send it elsewhere in the script upon the functions inception.
Huh, sorry I’m not sure I understand, I have to create an intValue in the player to keep track of the time? Otherwise with a documentation link or a roblox post that could help me
You can either create an IntValue to store it externally, or you can process the “Time” variable elsewhere outside of the OnServerInvoke function.
i.e:
script.Function.OnServerInvoke = function(Player, Time)
local IntValue = Instance.new("IntValue")
IntValue.Value = Time
IntValue.Name = Player.Name.."Countdown"
repeat wait(1) Time = Time - 1 until Time <= 0
return
end)
Okay, well I appreciate that I’m just doing an if = 0 with the return of the Function.
But There is one thing that I do not understand, if the event is called by several players in my short time or almost it will not be a problem?
There will be no problems no matter how many players invoke the RemoteFunction because calling an Event creates a new thread in the script - it wouldn’t pause anything except things waiting on the countdown which you would want anyway.
@TerryMichaelBrunk i try to make this but just give me error.
script.Function.OnServerInvoke = function(Player, Time)
local IntValue = Instance.new("IntValue")
IntValue.Value = Time
IntValue.Name = Player.Name.."Countdown"
repeat wait(1) Time = Time - 1 until Time <= 0
return
end
game.ReplicatedStorage.callMeHeh.OnServerEvent:Connect(function(plr)
if game.Players[plr.Name]:FindFirstChild(plr.Name.."Countdown").Value == 0 then
print("Time is 0");
end
script.Function:InvokeServer(30)
end)
You are trying to identify the value without setting it’s parent - something I left out of the original code since I was unaware with how you were handling the values.
script.Function.OnServerInvoke = function(Player, Time)
if not Player:FindFirstChild("Countdown") then
local IntValue = Instance.new("IntValue")
IntValue.Value = Time
IntValue.Name = "Countdown"
IntValue.Parent = Player
end
repeat wait(1) Time = Time - 1 until Time <= 0
return
end
game.ReplicatedStorage.callMeHeh.OnServerEvent:Connect(function(plr)
if game.Players[plr.Name]:FindFirstChild("Countdown").Value == 0 then
print("Time is 0");
end
script.Function:InvokeServer(30)
end)
@TerryMichaelBrunk actually not working I edited for create the value in a custom Floder but with that or without is not woking
script.Function:Invoke(1)
script.Function.OnServerInvoke = function(Player, Time)
if not Player:FindFirstChild("Countdown") then
local IntValue = Instance.new("IntValue")
IntValue.Value = Time
IntValue.Name = "Countdown"
IntValue.Parent = Player.DataStore
end
repeat wait(1) Time = Time - 1 until Time <= 0
return
end
game.ReplicatedStorage.callMeHeh.OnServerEvent:Connect(function(plr)
if game.Players[plr.Name].DataStore:FindFirstChild("Countdown").Value == 0 then
print("Time is 0");
end
script.Function:InvokeServer(30)
end)
And i changed RemoteFunction For binable becose studio don’t let me execute RemoteFunction in server script