Here's my script;
local Sword = script.Parent local Hitting = false local Dmg = script.Parent.Parent:WaitForChild('Stats').Damage Sword.Touched:Connect(function(hit) print('TOUCHED THE GOD') if hit.Parent:FindFirstChild('Humanoid') then if Hitting == false then Hitting = true if Hitting == true then return else local Enemy = hit.Parent:FindFirstChild('Humanoid') Enemy.Health = Enemy.Health - Dmg.Value wait(2) Hitting = false end end end end)
This is a Server Script inside of a part inside of a model.
Stats is a folder inside the model.
Inside stats we have the stats (duh) they are number values.
I'm not sure if I did something wrong but It's not doing damage.
Thank you for any feed back support and help.
I don't think there is any reason to use the hitting variable, but I think you needed to add GetPlayerFromCharacter
, because thehit.Parent
would just be the player, and the humanoid
is located inside of the players character
.
local Dmg = script.Dmg script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) local hum = player.Character.Humanoid hum.Health = hum.Health - Dmg.Value end)
Hopefully this works for you. If it did, please upvote and accept answer. If it didn't please comment. Thanks!
I think this is what is broken. On line 10, why did you make a if statement if that value just got immediately changed? That is why it is not working.