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
You need to do HumanoidToDamage.Parent.Humanoid:TakeDamage
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)