Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why my sword kills me when i pick it up?

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.