In my game, you can place blocks freely just by pressing “j”. Does anyone know how to change this script to limit it to only 1 cube per second?
RemoteEvent name: BIG CUBE
LocalScript in StarterPlayerScripts:
local UIS = game:GetService("UserInputService")
local Event = game.ReplicatedStorage["BIG CUBE"]
UIS.InputBegan:Connect(function(key,typing)
if typing then return end
if key.KeyCode == Enum.KeyCode.J then
Event:FireServer()
end
end)
Something like this, separate cooldown for every player
local Event = game.ReplicatedStorage["BIG CUBE"]
local CoolDown = 1
local Debounces = {}
Event.OnServerEvent:Connect(function(Player)
-- separate cooldown for each player
local Last = Debounces[Player.UserId]
-- if last time doesn't exist then set it
if not Last then
Debounces[Player.UserId] = 0
Last = 0
-- if difference between current time and last time is less than cooldown then do nothing
elseif time() - Last < CoolDown then
return
end
-- set last time to current time
Debounces[Player.UserId] = time()
local Part = Instance.new("Part")
Part.Size = Vector3.new(3,3,3)
Part.Parent = game.Workspace
Part.BrickColor = BrickColor.new("Ghost grey")
Part.Material = Enum.Material.SmoothPlastic
Part.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position + (Player.Character.HumanoidRootPart.CFrame.LookVector * 10))
end)