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

What is wrong with this onTouched script involving meshes and parts?

Asked by 6 years ago

What is wrong with this onTouched script? It's a brick (HitBox) hitting a mesh named B2, and I'm checking in output and all I see is "It isn't B2, It is B2!", which obviously is contradicting. So something is wrong and I can't seem to name it. B2 is in a model named Car, and the script is in HitBox.

local B2 = script.Parent.Parent.Parent.Car.B2
local HitBox = script.Parent

HitBox.Touched:Connect(function(Part)
    if Part.Name == B2 then
        print("It is B2!")
script.Parent.Parent.B3.Transparency = 0
script.Parent.Parent.B3.CanCollide = true

script.Parent.Parent.B1.Transparency = 1
script.Parent.Parent.B1.CanCollide = false
else
      print("It isn't B2, it is ".. Part.Name .."!")
      end
end)
0
Try if Part.Name == 'B2' ? T0XN 276 — 6y
0
I'm so dumb, should've thought of that. Thank you so much! TheBeaver101 28 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

line 5:

if Part.Name == B2 then

you are comparing incompatible types: Instance != String

there seem to be two solutions, one to compare the name, and one to compare the exact part with the touched one:

SOLUTION 1: if Part.Name == "B2" then

mind that there are "s surrounding the B2

SOLUTION 2: if Part == B2 then

Ad

Answer this question