Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Click to punch animation only works once but when you click again it doesn't?

So basically this is a Click to punch script. Every time you hit something that means that it does damage to thing its touching. But for some reason when you click one time it works perfectly fine but if you try do it again it doesn't. Here is the code Normal Script

local debounce = true

  

local function onServer(player,ID)

if debounce then

debounce = false

local character = game.Workspace:FindFirstChild(player.Name)

local humanoid = character.Humanoid

local punchAnimation = script.Punch:Clone()

punchAnimation.AnimationId = "https://roblox.com/asset/?id="..ID

local playerAnim = humanoid:LoadAnimation(punchAnimation)

playerAnim:Play()

wait(3)

debounce = true

end

end

  

game.ReplicatedStorage.AnimationEvents.Combo.OnServerEvent:Connect(onServer)

This is the damage script inside the Normal Script

local DamageValue = script.PunchDamage

DamageValue.Value = math.random(5,7)

  

local function touched(hit)

if hit.Parent:IsA("Model") then

local char = hit.Parent

local hum = char.Humanoid

if hum and char.Name ~= script.Parent.Parent.Name then

hum.Health = hum.Health - DamageValue.Value

script.Disabled = true

wait(.5)

script.Disabled = false

end

end

end

  

script.Parent.Touched:Connect(touched)

Local Script

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

  

local function buttonDown()

if player then

game.ReplicatedStorage.AnimationEvents.Combo:FireServer(02970353895)

end

end

  

mouse.Button1Down:Connect(buttonDown)

4 comments

0

you can get character with player.Character

0

because you said debounce instead of debounce == true

0

if you say debounce instead of debounce == true it still means debounce == true

0

i didnt say that anywhere

1 answer

Ok, so on the damage script, you used script.Disabled. If that is set to true while the script is doing something, the script will immediately stop; even if you do it in that script or if you want to finish the function.

To fix this, you will need to add a debounce variable to that damage and set it to true at start. Also, replace script.Disabled with debounce and swap true and false. Lastly, wrap around a if debounce == true then ... end on the function.

This discussion is preserved as it was. New answers, comments, and votes are closed.