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

My punch script isnt damaging players what do i do?

Asked by 4 years ago
Edited 4 years ago

I cant find what is wrong with it the animation is working fine but the damage and sound wont work heres my damage script and sound script

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local sound = game.ServerStorage.Punch:Clone()
        sound.Parent = char:WaitForChild("Head")
    end)
end)


game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player, humanoid)
    if humanoid.Health >= 10 then
        humanoid.Health = humanoid.Health - 10
    elseif humanoid.Health < 10 then
        humanoid.Health = 0 
    end

    player.Character.Head.Punch:Play()
end)

heres my local script

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

local anim = Instance.new("Animation")
anim.AnimationId = "https//www.roblox.com/asset/?id=3561679592"

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.C 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)


0
You’re checking if the hit parent is the player, not the actual enemy btw. Also, you’re firing the humanoid to the server, but you can’t send instances to the server, so instead send the humanoids name and parent, and try to find the humanoid on the server. Or, just put the touched event in a server script with the right hand as the parent so you can take damage on the server instantly ScrubSadmir 200 — 4y
0
^^^ basically you can’t send instances as arguments. SmartNode 383 — 4y

Answer this question