I’m doing a gun system,and I’m having problems to store data which is the MOST crucial to deal with exploits for the system since I don’t want an exploiter shoot earlier,here’s my script and I want to tell that It always goes to 2nd Shoot to Kick Function no matter what I do.
--Entire thing is in a function.
if Type == "Attack" then
if Player_Info_Table[Player] then
if Type == "Attack" then
if Value ~= "Shoot" and Value ~= "Melee" and Value ~= "None" and Value ~= "Cooldown" then
return
elseif Value == "Cooldown" and Value == "None" then
Gun_Object_Holder[Current_Gun_Object_Key]["Status"][Type] = Value
elseif (Value == "Melee" or Value == "Shoot") and Player_Info_Table[Player].Last_Attack then
local Current_Time = time()
local Time_Passed = Current_Time - Player_Info_Table[Player].Last_Attack
if Time_Passed < Gun_Object_Holder[Current_Gun_Object_Key].__inherit["Fire Rate"] then
Player:Kick("User Found With Exploits!")
else
Player_Info_Table[Player].Last_Attack = Current_Time
Gun_Object_Holder[Current_Gun_Object_Key]["Status"][Type] = Value
end
end
end
else
Player_Info_Table[Player] = {}
Player_Info_Table[Player].Last_Attack = time()
Gun_Object_Holder[Current_Gun_Object_Key]["Status"][Type] = Value
end
else
Gun_Object_Holder[Current_Gun_Object_Key]["Status"][Type] = Value
end
just dont kick players when they fail a sanity check
also if ur handing a cooldown separately on the client u could just have the cooldown be an attribute that the server sets and the client reads to completely prevent it
first of all why r u using the same if condition twice, it isnt neccessary.
also it’s recommended to make a warning system (like this abnormality has to fire 5 times in short succession) instead of kicking the player immediately)
a side note: do not use time() for millisecond precision, the better way of comparing time would be either to use os.clock() or tick() especially if you’re trying to get millisecond precision, it could provide an error which maybe result in a condition bug, if not it’s still better to use those methods rather than time()
also regarding attributes and instances I understand why you’d rather not use them, especially if you’re entire framework relies on things being done through scripts and remote events having attributes randomly used for one replication use case isn’t the way to go in terms of consistency, have the client do its own cooldown checking and have a module script for constants that shares the fireRate value they both fetch from that, if someone is exploiting on the client they may bypass the cooldown but in the end you’re doing validation on the server and not registering the bypassed hit so only the client exploiting will see what its doing.
finally for structural purposes in your code, you should consider early return statements by inversing the conditionals statements, for example:
if not Player_Info_Table[Player] then
return
end
if Type ~= "Attack" then
return
end
and so on, it avoids crazy nested conditionals and makes reading the code much better