Title says it, is there any method to creating cooldowns globally for each player but not having the game filled with thousands of remote events and such? My idea right now is to create tables unique to each player with their respective moves’ cooldown values, but i don’t know how to implement that.
Just the idea of how to make such a system would be cool, but even better if anyone can help me make one with my idea if its possible
Try to use a value Instance and add it to a debris service
local deb = game:GetService("Debris")
When creating a cooldown
local CooldownValue = Instance.new("IntValue")
CooldownValue.Parent = CooldownFolder
CooldownValue.Name = "Punch"
deb:AddItem(CooldownValue, CooldownSeconds) -- Punch Cooldown
When checking if there is a cooldown
if not CooldownFolder:FindFirstChild("Punch") then -- you will have to use a folder
-- Do stuff then add another Cooldown
end
Would security be a concern with this method? I heard from other sources that adding and creating object values in a player would expose it to client modification resulting in cheating
I’m not too sure, but if you made it on the server and checked if the cooldown was changed on the server, I don’t think so.
I think if the cooldown was checked on the server, and you tried confirming it through the client, then there probably would be a security issue.
No, they can’t change it other than for themselves. It’s fine.
But I imagine you’d want the cooldown to reset whenever the character respawns, no? In that case you should have the folder in the character or just have the value parented to the Tool or script itself.
I mean, to be honest this method isn’t what I’m looking for since it creates too many variables, which might become hard to manage? So what I’m trying to do is whenever a player joins the game, create a table specifically for that player, then add in moves variables to that table, but then also have those moves have their own data like cooldowns and such. Sorry for the bad wording but idrk how to describe it
Didn’t understand very well what you said, honestly.
But no, it’s fine to have a folder in the character and put cooldown values there, and then check in the scripts if there’s a cooldown with the move’s name there.
I’ll try digging deeper in that case, will come back to this later
Why would you want this anyway? Is a bunch of remote events too data-heavy on your game, or is it just a personal preference, or is there even more to that?
I think i got it.
local m1Data = {
Name = "M1",
CD = 10000
}
local m2Data = {
Name = "M2",
CD = 1000020
}
local movesTable = {m1Data, m2Data}
doing it like this would probably make it better organized and better managed since it’s data on the server, not something that exploiters can tamper with. I’ll have to think it thru more thoroughly if I wanna actually make this work tho
its jst personal preference cause doing haat would make it kinda hard to manage, at least for me
I like the idea of it a lot, but imo it just seems much easier to have it handled by remote events, although if there ever is a system that isn’t data heavy, proficient in what it can do, and that looks clean, I’d probably switch over to it.
As of now though, I just have cooldowns managed on a server script, and a remote event that fires whenever a tool is activated.
I got a lot of expectations for this one actually since I’ve tried your method b4 but didn’t like it, I’ll test it out lyk how practical this is ig
Well then what do you prefer and why?
I found it pretty messy that I have to fire events every time I do something and such, and because of the latency issue between clients and the server with remote events, so I decided to start creating a different approach than remotes/creating objectvalues
I have found a solution, RemoteFunctions are the key apparently
Client side:
local cooldownHandler = game.ReplicatedStorage.CDHandler --assuming there's a RF there
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, gp)
if gp then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local m1CD = cooldownHandler:InvokeServer("M1")
if m1CD > 0 then return end
for i, v in pairs(char:WaitForChild("Humanoid"):GetPlayingAnimationTracks()) do
if v.Name == "M1" then return end
end
--code down here bla bla
end
end)
Server side:
local Players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local events = replicatedStorage:WaitForChild("Events")
local cooldownHandler = events.CDHandler
local combatHandler = events.CombatHandler
local playerData = {}
local function getCDofMove(player, MoveName)
return playerData[player.UserId][MoveName].CD
end
local function playerAdded(player)
local defaultMoves = { --you can add more in here afterwards
["M1"] = {
Name = "M1",
CD = 0
}
}
playerData[player.UserId] = defaultMoves
end
local function playerRemoving(player)
playerData[player.UserId] = nil
end
cooldownHandler.OnServerInvoke = getCDofMove
Players.PlayerAdded:Connect(playerAdded)
Players.PlayerRemoving:Connect(playerRemoving)
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end
Very well elaborated question, thank you.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.