Why Wont My Punch Script Work?

Everything in my script works except for when its supposed to take damage, its a local script and uses a remote event to damage the player.

–Here’s The Script

local plr = game.Players.LocalPlayer

local Players = game:GetService("Players")

local Playing = false

local mouse = plr:GetMouse() or task.wait(plr:GetMouse())


local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local Animator = hum:WaitForChild("Animator")

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://18239370085"

local animTrack = Animator:LoadAnimation(anim)

-- 18239203600

mouse.Button1Down:Connect(function ()
	if mouse and Playing == false then
		Playing = true

		for _, player in pairs(Players:GetChildren()) do
			local OneCharacter = player.Character or player.CharacterAdded:Wait()
			local distance = (char.PrimaryPart.Position - OneCharacter.PrimaryPart.Position).Magnitude

			if distance < 20 and player.Name ~= plr.Name then
				game.ReplicatedStorage.PlayerPunch:FireServer(OneCharacter)
			end
		end
		animTrack:Play()
		animTrack:AdjustSpeed(animTrack.Length * 1.5)
		task.wait(animTrack.Length * 1.5)
	end
end)

while true do
	if Playing == true then
		task.wait(animTrack.Length * 2)
		Playing = false
	end
	task.wait(0.001)
end

–Here’s The Server Script

game.ReplicatedStorage.PlayerPunch.OnServerEvent:Connect(function (plr, OneChar)
	local hum = OneChar:WaitForChild("Humanoid") or OneChar:FindFirstChild("Humanoid")
	hum.Health -= 10
	print("tookHealth")
end)

4 Likes

i think you dont need to use both waitforchild or findfirstchild at the same time, try just using:

local hum = OneChar:FindFirstChild(“Humanoid”)

if hum then
hum:TakeDamage(10)
end
2 Likes

It still doesn’t seem to work, any other suggestions?

2 Likes

did it print anything on the server like add a print on the onserverevent

1 Like

yeah add a print statement so we would know if the char is passed through the remote event or no

are you testing against a player or against a dummy/ai bot?

it wont work if your testing against a bot cause bots are not categorized as players

1 Like

I guess my brain just wasn’t braining

lol nah its fine i also make this mistake often

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.