Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why my sword kills me when i pick it up?

Asked by 2 years ago

when I pick it up it kills me and I don't know why, here is the code:

local Tool = script.Parent

while true do
Tool.Handle.Touched:Connect(function(hit) if hit.Parent ~= Tool.Parent then hit.Parent:WaitForChild("Humanoid") hit.Parent.Humanoid:TakeDamage(5) wait(1) end wait(0.1) end) wait(0.1) end

1 answer

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
2 years ago

When the tool is touched ( so either in your hand or I guess you hit someone with it ) it will damage that player. if hit.Parent ~= Tool.Parent that should in theory work, but if the player has an accessory like a necklace or an egg on their head, that if will return true (since it's the player's necklace, not the player itself) To fix that just add another check, like if hit.Parent~=Tool.Parent and hit.Parent.Parent~=Tool.Parent this should work

Ad

Answer this question