someone told me spawn() is laggy and bad and courotine is better idk how to use courotine
In this case, we don’t need to use coroutine. We will use a function called delay(), which basically takes two argument. The first argument needs to be how many seconds to pause before starting the function, which will be specified in the 2nd parameter.
isnt delay the same thing as spawn and still laggy
Both of these functions are not laggy, as long as you don’t spawn too many threads in a script.
anyways how would i transition my scripts so exploiters cant do anything
We are gonna use something called a Debounce Table, where it should be stored in server script. This table will be a dictionary, where each key’s name is a player’s name/UserId in the server and the value is kinda like debounce values. Assume something like this:
local DebounceTable = {
ItzMeZeus_IGotHacked = true; —this means my debounce is on, so I can’t fire the Attack remote event.
You_AreCool = false —this means his debounce is off, so he can fire the attack remote event
}
What we trying to do is to make sure all players in the game has their name in this dictionary, and remove their key whenever they leave the game. To do so:
game.Players.PlayerAdded:Connect(function(plr)
DebounceTable[plr.Name] = false
end)
game.Players.PlayerRemoving:Connect(function(plr)
DebounceTable[plr.Name] = nil
end)
Now, whenever someone fires the event, we will first check if their debounce value is false, if it is, we will make their debounce value to true and spawn a thread where it will change back their debounce value back to false after a certain amount of cooldown time you want. So it will be like:
event.OnServerEvent:Connect(function(plr)
if DebounceTable[plr.Name] == false then
DebounceTable[plr.Name] = true
delay(3,function()
DebounceTable[plr.Name] = false
Attack() — do your stuffs here.
else return end
end)
and the local script and stunning (pausing the function)?
No no, we let the client to STILL have the cool down, and that script will handle exploiters.
this still doesn’t solve my problem on how to pause the function when a player gets stunned.
What you can do is when they get stunned, set the value to true so they can’t attack.
wont work if the player was already attacking.
im just going to give up i already searched it nobody can answer
how will it work if the player was already attacking…?
I think you are looking for something like these.
If you make the whole thing based off of an animation, then when you stop the animation, it will stop the current skill.
Then you can set dedicate a whole animation level to skills if some moves can’t be stopped by some.
EG if the animation has priority 2 then its a skill (Can be attacking or using an ability)
And maybe a data table along the lines of
Ability Name – Reference to the ability move.
Animation Level – How hard the animation is to cancel
Animation Stop Level – What level of animations it can stop, so if this is 500, it will stop animations <= 500.
Exceptions – If you want to add certain exceptions, for example, “Flame ball” will go through “Ice sheild” even when the priorities are different.
(I got no clue, but I was looking into this now and this is how I will try to make mine)
Lemme know what you think.
If I remember, the issue I was having was me being a heavily inexperienced programmer at the time and not understanding the relationship between server and client, hence, it working player-player but not player-server.
But as Lordinu said, @lilzy7, if you do your system based on animations, you can simply have a function where it sends a remoteevent signal to the attacked entity to :Stop() the attack animation, therefore allowing for the stun to actually serve its purpose.