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

Script is deleting characters instead of listed names?

Asked by 6 years ago


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.

0
Hmm maybe if I used findfirstchild THEROBLOXAIN2 15 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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)
0
Thanks THEROBLOXAIN2 15 — 6y
Ad

Answer this question