So this localscript is supposed to throw a punch animation, and if the punch hit another player it should lose -10 health. The thing is that the animation works okay, but it does not give any damage on the other player. How can I fix this/improve my script?
local userInputService = game:GetService("UserInputService") local PunchValue = false local db = false local leftPunch = script.LeftPunch local rightPunch = script.RightPunch wait(0.1) local player = game.Players.LocalPlayer local char = player.character local hum = char.Humanoid local leftHand = char.LeftHand local rightHand = char.RightHand local humanoidRootPart = char.HumanoidRootPart local leftPunchTrack = hum:LoadAnimation(leftPunch) local rightPunchTrack = hum:LoadAnimation(rightPunch) userInputService.InputBegan:Connect(function(input, gameProcessedEvent) if input.KeyCode == Enum.KeyCode.F and db == false then db = true print("Player pressed down the F key") if PunchValue == false then PunchValue = true leftPunchTrack:Play() elseif PunchValue == true then rightPunchTrack:Play() PunchValue = false leftHand.Touched:connect(function(hit) print(hit) if hit == humanoidRootPart then local human = hit:FindFirstChild("Humanoid") human.Health = human.Health -10 end end) rightHand.Touched:connect(function(hit) print(hit) if hit == humanoidRootPart then local human = hit:FindFirstChild("Humanoid") human.Health = human.Health -10 end end) end wait(1.5) db = false end end)
Thanks, Xsodar
if this is a localscript, Try using RemoteEvent beacuse The damage will not be in the server. And also I recommend you to use
human:TakeDamage(Damage_Here)
instead of using:
human.Health = human.Health - 10
I am not sure if i can make a Complete Script To fix it.
but if you're not sure what RemoteEvents are i suggest you to read this
I hope it atleast give you a little bit of help