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

Trail Effects Sensor Only Disables One Rather Than Four?

Asked by 6 years ago
Edited 6 years ago

Hi folks, back with another error that I really would like to get to the bottom of. I have sensors located along my track, each of them are supposed to either disable the trail effects from the car whilst airborne or enable them when back on the ground and has touched the sensor. Here's what I've tried, it works but only for one and none of the others.

script.Parent.Touched:Connect(function(Active)
    for i,v in pairs(Active.Parent:GetChildren())do
    if v.Name == "TrailEffects" then
        spawn(function()
        v.Parent.TrailEffects.Trail.Enabled = false
    end)
    end
    end
    end)

As you can see, it's a short script and I'm no doubt missing a lot, but I'm still trying to learn new techniques and such. Thank you all sincerely for any help you can provide me with. Hopefully I can give back to you all when scripting becomes one of my strong points.

1 answer

Log in to vote
0
Answered by 6 years ago

It's because by calling

v.Parent.TrailEffects.Trail.Enabled = false

you go to the same object (in other words - first object named 'TrailEffects') Change v.Parent.TrailEffects to just v, so it will be:

v.Trail.Enabled = false
0
Thanks, it works fantastically now. I didn't realise it was just a minor error, I was worried I would have to double the amount of lines I have now. Thanks again! NovaCometT2 9 — 6y
Ad

Answer this question