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

I also have the starter character local script and this might not be working?

Script: local player = game.Players.LocalPlayer local db = true local damaged = false

local anim = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/asset/?id=4556329390"

game.players.localplayer.Character:waitforchild("righthand").touched:connect(function(hit) if hit.parent:findfirstchild("humanoid")and not db and not damaged and hit.parent.humanoid ~= game.Players.localplayer.character.humanoid then if game.Players.localplayer.character.humanoid.health > 0 then damaged = true game.ReplicatedStorage.Punch:FireServer(hit.parent.humanoid) end end end)

game:GetService("UserInputService").inputbegan:connect(function(input, event) if input.keycode == Enum.KeyCode.F and db then db = false local playanim = game.Players.LocalPlayer.Character:waitforchild("humanoid"):loadanimation(anim) playanim:play() wait(0.8) damaged = false db = true end end)

1 answer

✓ Accepted answer

Try this:

local player = game.Players.LocalPlayer 
local db = true 
local damaged = false

local anim = Instance.new("Animation") 
anim.AnimationId = "http://www.roblox.com/asset/?id=4556329390"

player.Character:WaitForChild("RightHand").Touched:Connect(function(hit) 
    local hitHumanoid = hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid")
    local playerHumanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")


    if hitHumanoid and playerHumanoid and not db and not damaged and hitHumanoid ~= playerHumanoid and playerHumanoid.Health > 0 then 
        damaged = true 
        game.ReplicatedStorage.Punch:FireServer(hitHumanoid)
    end 
end)

game:GetService("UserInputService").InputBegan:Connect(function(input, event) 
    local playerHumanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")

    if input.keycode == Enum.KeyCode.F and db and playerHumanoid then 
        db = false 
        local playanim = playerHumanoid:LoadAnimation(anim) 
        playanim:play() 
        wait(0.8) 
        damaged = false 
        db = true 
    end 
end)

2 comments

0

Thanks!

0

It didn't work for me but its probally just my problem

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