What do you want to achieve? Keep it simple and clear!
Topic says everything
What is the issue? Include screenshots / videos if possible!
My problem is what task.wait and more extended ways of delays, are not giving any result
What solutions have you tried so far? Did you look for solutions on the Developer Hub? i tryed using a cooldown with debounce, task.wait cooldown and etc., they are all not stopping script from executing
Client Code:
local player = game:GetService("Players").LocalPlayer
local UIS = game:GetService("UserInputService")
local ClientFunctions = require(game:GetService("ReplicatedStorage").ClientFunctions)
local PhotonSpawn = workspace.Events.PhotonSpawn
local ReturnUpgrade = workspace.Events.ReturnUpgrade
UIS.InputBegan:Connect(function(inp, eng_proc)
if eng_proc then
end
if inp.KeyCode == Enum.KeyCode.E then
PhotonSpawn:FireServer(ReturnUpgrade:InvokeServer(player, "PhotonUpgrades" ,"Bulk"))
ClientFunctions:TextTransparent(player.PlayerGui.GameGUI.TextLabel, "increase", 150)
ClientFunctions:TextTransparent(player.PlayerGui.GameGUI.TextLabel, "decrease", 150)
end
end)
local PlayerManager = require(script.Parent.PlayerManager)
local ServerFunctions = {}
function ServerFunctions:SpawnPhoton(player, amount)
local Models = game:GetService("ServerStorage").Models
PlayerManager.SetValue(player, "Values", "Photons", PlayerManager.GetValue(player, "Values", "Photons") + amount)
for i=1,amount do
local Clone = Models.Photon:Clone()
Clone.Parent = workspace.FirstMap.Photons
end
end
return ServerFunctions
in each of them i tryed to issue cooldown, but it never worked correctly. So i basically need help with debouncing it i guess
On client, you are asking to server by InvokeServer, Server returns a valid amount. Then Client/Exploiter fires the PhotonSpawn remote, with whatever value they want, idk inf*
Then Server listen the call and run the module function to create the photons exploiter said…:
So, you dont need the first InvokeServer, you can check the allowed amount for that player when the module is going to do the for i=1, amount do to clone the photons.
You could add the debounce inside that module too, to check that player is allowed to create more photons. You could use a table that stores the timestamp of the last time the player created photons, or a value somewhere that toggles after certain amount time since the last photon creation
local player = game:GetService("Players").LocalPlayer
local UIS = game:GetService("UserInputService")
local ClientFunctions = require(game:GetService("ReplicatedStorage").ClientFunctions)
local PhotonSpawn = workspace.Events.PhotonSpawn
local ReturnUpgrade = workspace.Events.ReturnUpgrade
-- cooldown for local player
local cooldowntime = 5
local cooldown = false
UIS.InputBegan:Connect(function(inp, eng_proc)
if cooldown then return end
if eng_proc then
end
if inp.KeyCode == Enum.KeyCode.E then
cooldown = true
PhotonSpawn:FireServer(ReturnUpgrade:InvokeServer(player, "PhotonUpgrades" ,"Bulk"))
ClientFunctions:TextTransparent(player.PlayerGui.GameGUI.TextLabel, "increase", 150)
ClientFunctions:TextTransparent(player.PlayerGui.GameGUI.TextLabel, "decrease", 150)
task.wait(cooldowntime)
cooldown = false
end
end)
Then you should also put a cooldown on the event to avoid any exploiter doing no cooldown shenanigans
local cd = {} -- seperate cooldown for each player since this is a not a local script
PhotonSpawn.OnServerEvent:Connect(function(player, amount)
if table.find(cd, player) return end
table.insert(cd, player)
ServerFunctions:SpawnPhoton(player, amount)
task.wait(5) -- same cd as in the localscript
table.remove(cd, table.find(cd, player))
-- thanks for pointing out the mistake devpeashie
end)
Was this what you were looking for?
Also as @Dev_Peashie said, the client shouldn’t tell the server how many photons should be produced
Just something to add, table.remove(cd, player) wont work, cause it needs an int value. Would be: table.remove(cd, table.find(cd, player))
Or a dictionary, almost the same.
I have currently added an client sided function(in client module) to return some client data, as like as cooldown, but also issue that cooldown on server in same time. And i assume it works correctly. Thanks