hello there! I’ve been going at this for a while and I still can’t get the debounce to work. All help would be appreciated <3
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local ReplicatedS = game:GetService("ReplicatedStorage")
local Freeze = ReplicatedS:WaitForChild("Freeze")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://"
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"
local debounce = false
player.Chatted:Connect(function(msg)
if msg == "Immobilus" or "Consto" then
if Character.Witch.Value == true then
if Character.Magic.Value > 40 then
mouse.Button1Down:Connect(function()
debounce = true
local Anim = Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
Sound:Play()
Anim:Play()
Freeze:FireServer(mouse.Target)
end)
wait(10)
debounce = false
end
end
end
end)
There is no if statement including the debounce variable.
example:
local debouce = false
player.Chatted:Connect(function()
if debounce then
debounce = false
else
debounce = true
end
end)
or
local debouce = false
player.Chatted:Connect(function()
if not debounce then
debounce = true
end
wait(10) -- wait() is depreciated, use task.wait(10) instead
debounce = false
end)
I updated it to look more like the second example you gave me but still didn’t work. Did I go wrong somewhere?
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local ReplicatedS = game:GetService("ReplicatedStorage")
local Freeze = ReplicatedS:WaitForChild("Freeze")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://"
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"
local debounce = false
player.Chatted:Connect(function(msg)
if msg == "Immobilus" or "Consto" then
if not debounce then
debounce = true
if Character.Witch.Value == true then
if Character.Magic.Value > 40 then
mouse.Button1Down:Connect(function()
local Anim = Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
Sound:Play()
Anim:Play()
Freeze:FireServer(mouse.Target)
end)
end
end
end
end
task.wait(10)
debounce = false
end)
Simply have the debounce part inside the if statement itself (where you check for it).
This will work out for you (my version), modify if you want.
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local ReplicatedS = game:GetService("ReplicatedStorage")
local Freeze = ReplicatedS:WaitForChild("Freeze")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://"
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"
local debounce = false
player.Chatted:Connect(function(msg)
if msg == "Immobilus" or "Consto" then
if debounce then return end
debounce = true
if Character.Witch.Value == true then
if Character.Magic.Value > 40 then
mouse.Button1Down:Connect(function()
local Anim = Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
Sound:Play()
Anim:Play()
Freeze:FireServer(mouse.Target)
end)
end
end
task.wait(10)
debounce = false
end
end)
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local ReplicatedS = game:GetService("ReplicatedStorage")
local Freeze = ReplicatedS:WaitForChild("Freeze")
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://"
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"
local debounce = false
player.Chatted:Connect(function(msg)
if msg == "Immobilus" or msg == "Consto" then
if Character.Witch.Value then
if Character.Magic.Value >= 40 then
mouse.Button1Down:Connect(function()
if debounce then return end
debounce = true
local Anim = Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
Sound:Play()
Anim:Play()
Freeze:FireServer(mouse.Target)
task.wait(10)
debounce = false
end)
end
end
end
end)