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

Help with damage on touch hurting the owner?

On the press of a key it clones from lighting to the players character, and changes a string value in the clone to the the players name. With ~= it doesn't hurt the player who presses the key, but it also doesn't hurt anything else. If I change it to == it hurts the character, but also hurts anything else. Why is this? Shouldn't it only not hurt someone with the name of the string's value?

Also, if anyone knows a way to make it so that the clone can't hurt the person who cloned it, I'd appreciate it if you shared.

	humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid and script.Parent.Parent.Name ~= script.Parent.owner.Value then --script.Parent.Parent = Character
	hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health -7

1 answer

Your problem is that on line 2 you are saying 'and script.Parent.Parent.Name' that will return the name of the parent of the parent of the script. What you want to do is to get the players name like so:

humanoid = hit.Parent:FindFirstChild("Humanoid")
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if humanoid and plr.Name ~= script.Parent.owner.Value then

Hope this helps and have a great day scripting!

1 comment

0

Thanks

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