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

How do I make this error disappear? Punching

Asked by 5 years ago

I posted something like this but it never worked so i decided to make a whole new script and now I need your help to make it work

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local PunchEvent = ReplicatedStorage:WaitForChild('Punch')
PunchEvent.OnServerEvent:Connect(function(hi)
    local ctr = hi.Character 
    local hum = ctr.Humanoid
    local LeftArm = ctr:FindFirstChild("Left Arm")
    local Power = hi.StatsFolder.StrengthValue.Value
    LeftArm.Touched:Connect(function(PlayerWhoSent, HumanoidToDamage, Power)
        print("touched")
        if HumanoidToDamage.Parent and HumanoidToDamage.Parent.Humanoid then
            HumanoidToDamage:TakeDamage(Power)

        end
    end)
end)

the error is attempt to index local 'HumanoidToDamage' (a nil value) this is a punch script and i have made another script for the punch animation in starter pack if needed then tell me. if i do print(HumanoidToDamage) it prints nil

0
Touched event only has 1 parameter which is the PartThatTouched parameter User#23365 30 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

You need to do HumanoidToDamage.Parent.Humanoid:TakeDamage

0
Wait nvm, how are you supposed to get HumanoidToDamage and Power from a touched event? Potatofoox 129 — 5y
0
um use the parameters of the touched event User#23365 30 — 5y
0
https://i.gyazo.com/ef58fb3c7a31bf1861613c9416b22c6f.png touched does not return those parameters. Potatofoox 129 — 5y
Ad
Log in to vote
0
Answered by
Vulkarin 581 Moderation Voter
5 years ago

The reason for your error is because the Touched event does not return the values you seem to expect it will

The return value of touch is the part that touched, so you could do

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local PunchEvent = ReplicatedStorage:WaitForChild('Punch')
PunchEvent.OnServerEvent:Connect(function(hi)
    local ctr = hi.Character 
    local hum = ctr.Humanoid
    local LeftArm = ctr:FindFirstChild("Left Arm")
    local Power = hi.StatsFolder.StrengthValue.Value
    LeftArm.Touched:Connect(function(toucher)
        local humanoid = toucher.Parent and toucher.Parent:FindFirstChild("Humanoid") or nil
        if humanoid then
            humanoid:TakeDamage(Power)
        end
    end)
end)
0
idk y but everything is working but the dummy or whatever u call isn't taking damage HappyTimIsHim 652 — 5y

Answer this question