I am working on a script that lets the player mine, I want to have a delay on the RemoteFunction but don’t know how to do it. I know if I put the delay variable outside of the function the delay will be shared by all players and I know if I put the delay variable inside the function it will reset to false each time it is called. Please someone help me on this, thanks.
What you’re doing should work fine. You could try using
delay(yourtime, function()
-- call the remote from here
end)
thank you very much! This will help for most of the stuff in my game.
hmm, it seems its not working I can still mine almost instantly, is the delay in seconds?
You need to setup some logic. Before they mine, you need to make sure they are able to actually do it. If they are able to mine, then set the ‘CanMine’ variable to false. Wait the specified amount of time, fire the remote event, then set ‘CanMine’ to true, allowing them to mine again.
local CanMine = true;
function Mine()
if CanMine then
CanMine = false;
-- Fire your remote
wait(yourtime)
CanMine = true
end
end)
where would I store this variable? As a int value in there Character?
Doesn’t really matter… If you are checking on the server, then you should implement a “CanMine” variable/value on the server
If I put it in a script will it be shared by all the players? Or should I put it in a PlayerAdded
Uh, localscripts don’t get shared between players. If you’re talking about a variable inside of a server script then yes, it applies to the whole server. If you want to have a variable for every player on the server, then use a table.
local PlayerTables = {};
PlayerTables[Player.Name].CanMine = true
(just an example)
Ok I think I might make it a value in the player that way exploiters cant fire it without a delay
If you’re checking and setting the value on the server then it should be fine in terms of exploiting.
