So, right now I have a script that's functioning really well except for one problem, which is the player can spam the letter Z and it starts to lag the game. I understand it's debounce, but when in the script should I place it, or is there a replacement for debounce that i can put, like wait()? The variable "Ready" I have in my script is the current debounce I have, but it still allows the player to spam Z.
player = game.Players.LocalPlayer
character = player.CharacterAdded:wait()
humanoid = character:WaitForChild('Humanoid')
mouse = player:GetMouse()
goroBall = Instance.new("Part", game.Workspace)
goroBall.Shape = "Ball"
goroBall.CanCollide = false
goroBall.Material = "Neon"
goroBall.BrickColor = BrickColor.new("Bright yellow")
goroBall.Size = Vector3.new(15,15,15)
uis = game:GetService("UserInputService")
uis.InputBegan:connect(function(input,gpe)
local Ready = true
if input.KeyCode == Enum.KeyCode.Z and Ready == true then
Ready = false
for i = 1,5 do
local goro = goroBall:Clone()
goro.Parent = game.Workspace
goro.CFrame = character.Torso.CFrame * CFrame.new(0,0,-15)
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(1e8,1e8,1e8)
bv.Velocity = character.Torso.CFrame.lookVector * 50
bv.Parent = goro
Ready = true
end
end
end)

6 comments
err sorry, but im still able to spam "z" and it wont work
Ehh sorry, I edited by answer, I made a mistake
You should move the
ready = trueoutside, above, the for loop.wait lol im confused, if "Ready" is false, at the beginning, script won't run because it's false right? or is it meant to be like that...?
sorry it worked nvm XD
ok sorry one last question, i wanted the script to send out multiple spheres at one time, but instead it only sends out one sphere every few seconds. Is this the result of using a for loop, and if so which loop do i use? while true do?