#how can i prevent spamming on an animation script
41 messages · Page 1 of 1 (latest)

local bd
--some event to fire it
if not db then
db = true
--some randum stuff
wait(sometime)
db = false
end
at the --some event to fire do i create an event to trigger it?
yes
and at the random stuff?
there you play your animation
the animation script?
ok just send the script
`local Tool = script.Parent
local AnimationR15 = script:WaitForChild("AnimationR15", 1)
local AnimationR6 = script:WaitForChild("AnimationR6", 1)
Tool.Activated:Connect(function()
local Character = Tool.Parent
if Character then
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
if Humanoid then
local LoadedAnim = nil
if Humanoid .RigType == Enum.HumanoidRigType.R15 and AnimationR15 then
LoadedAnim = Humanoid:LoadAnimation(AnimationR15)
elseif Humanoid .RigType == Enum.HumanoidRigType.R6 and AnimationR6 then
LoadedAnim = Humanoid:LoadAnimation(AnimationR6)
end
if LoadedAnim then
LoadedAnim:Play()
end
end
end
end)`
local Tool = script.Parent
local AnimationR15 = script:WaitForChild("AnimationR15", 1)
local AnimationR6 = script:WaitForChild("AnimationR6", 1)
local db
Tool.Activated:Connect(function()
if db then return end
db = true
local Character = Tool.Parent
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
if not Humanoid then return end
local LoadedAnim
if Humanoid.RigType == Enum.HumanoidRigType.R15 and AnimationR15 then
LoadedAnim = Humanoid:LoadAnimation(AnimationR15)
elseif Humanoid.RigType == Enum.HumanoidRigType.R6 and AnimationR6 then
LoadedAnim = Humanoid:LoadAnimation(AnimationR6)
end
if LoadedAnim then
LoadedAnim:Play()
end
task.wait(.1)
bd = false
end)
thank you
** You are now Level 1! **
the script has a little problem
it dosen't put a cooldown on it it just lets u push once
and then dosen't let u push again
or use the tool
the push tool
try using local db = false at line 4
and i still have a little question
?
can u help me put a cooldown on my main script too?
ok
local playerRoot = player.Character:FindFirstChild("HumanoidRootPart")
local pushRoot = toPush:FindFirstChild("HumanoidRootPart")
if(playerRoot and not playerRoot:FindFirstChild("PushF") and pushRoot and not pushRoot:FindFirstChild("PushF") and (playerRoot.Position - pushRoot.Position).magnitude <= 6) then
local pushF = Instance.new("BodyVelocity")
pushF.Name = "PushF"
pushF.MaxForce = Vector3.new(100000, 100000, 100000)
pushF.Velocity = (-pushRoot.CFrame.lookVector) * 50
pushF.Parent = pushRoot
wait(0.3)
pushF:Destroy()
end
end)```
where is that script?
in the tool
for me the last line is maked red an idk why but try this
local db = false
script.Parent.Push.OnServerEvent:Connect(function(player, toPush)
if db then return end
db = true
task.delay(.5, function() db = false end)
local playerRoot = player.Character:FindFirstChild("HumanoidRootPart")
local pushRoot = toPush:FindFirstChild("HumanoidRootPart")
if playerRoot and not playerRoot:FindFirstChild("PushF") and pushRoot and not pushRoot:FindFirstChild("PushF") then
if (playerRoot.Position - pushRoot.Position).Magnitude > 6 then return end
local pushF = Instance.new("BodyVelocity")
pushF.Name = "PushF"
pushF.MaxForce = Vector3.new(100000, 100000, 100000)
pushF.Velocity = (-pushRoot.CFrame.lookVector) * 50
pushF.Parent = pushRoot
wait(0.3)
pushF:Destroy()
end
end)
dsn't work
** You are now Level 2! **
try re coppying it, i missed a "then"
it works thanks