So I have this script inside my sword, and it seems to throw up an error when it touches anything other than a player, and I can't seem to find a way to make it still do damage to a humanoid if it touches something that doesn't contain a Humanoid
I've tried WaitForChild, but it throws up an infinite yield error
Av = 15 --Attack Value tool = script.Parent function tagHumanoid(humanoid,killer) if humanoid and killer then local tag = Instance.new("ObjectValue") tag.Name = "creator" tag.Value = killer tag.Parent = humanoid end end script.Parent.Handle.blade.Touched:connect(function(p) local plr = game.Players:GetPlayerFromCharacter(tool.Parent) if script.Parent.CanDamage.Value == true then script.Parent.CanDamage.Value = false local humanoid = p:FindFirstChild("Humanoid") p.Parent.humanoid:TakeDamage(Av) tagHumanoid(humanoid, plr) wait(1) script.Parent.CanDamage.Value = true if p.Parent.Humanoid.Health < 1 then print("Player Has Died") end end end)
You dont check if what it touches is a player so if it isnt a player it trys to find a thing u would only find in a player
Av = 15 --Attack Value tool = script.Parent function tagHumanoid(humanoid,killer) if humanoid and killer then local tag = Instance.new("ObjectValue") tag.Name = "creator" tag.Value = killer tag.Parent = humanoid end end script.Parent.Handle.blade.Touched:connect(function(p) local plr = game.Players:GetPlayerFromCharacter(tool.Parent) if script.Parent.CanDamage.Value == true and p.Parent:FindFirstChild("Humanoid") then -- checking if its a player script.Parent.CanDamage.Value = false local humanoid = p.Parent:FindFirstChild("Humanoid") humanoid:TakeDamage(Av) tagHumanoid(humanoid, plr) wait(1) script.Parent.CanDamage.Value = true if p.Parent.Humanoid.Health < 1 then print("Player Has Died") end end end)