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

Script is deleting characters instead of listed names?



script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name == "Ship1" or "Ship2" or "Ship3" or "Ship4" or "Ship11" or "Ship22" or "Ship33" or "Ship44" or "Demolition Ship" or "Demolition Ship1" then
		
		hit:Destroy()

	end
end)

It is meant to delete what is named but deletes everything even if its not listed in the list.

1 comment

0

Hmm maybe if I used findfirstchild

1 answer

✓ Accepted answer

You are writing "or" repeatedly without following it with the original conditional "hit.Parent.Name == (name)", that's what is making your script error. In the following fixed version of your script, I've put up all your variables inside a table and have the function just loop through the table searching for a matching name, this way its much more compact and organized.

local Ships = {"Ship1", "Ship2", "Ship3", "Ship4", "Ship11", "Ship22",
"Ship33", "Ship44", "Demolition Ship", "Demolition Ship1"}

script.Parent.Touched:Connect(funciton(hit)
	for i,ship in pairs(Ships) do
		if hit.Parent.Name == ship then
			hit:Destroy()
			break
		end
	end
end)

1 comment

0

Thanks

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