Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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)
0
you can get character with player.Character wwwdanielwww 5 — 5y
0
because you said debounce instead of debounce == true cherrythetree 130 — 5y
0
if you say debounce instead of debounce == true it still means debounce == true Joshument 110 — 5y
0
i didnt say that anywhere WillBe_Stoped 71 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

Ad

Answer this question