I need help with a VehicleSeat Disabler

Alright, so i’m new in scripting, and i need some help in this script.

It’s a “Function on-touched/hit” script that I’ve doing for the last hour, and this is what I’ve done so far.

but there’s a problem, when the parent “hits” with another one it is supposed to disable the VehicleSeat/DriveSeat
but it doesn’t, and there’s where i need help.

I believe the problem is that you’re trying to use .Disabled on DriveSeat.Throttle, which I believe has no disabled property. You’ll want to only use .Disabled after the DriveSeat itself, like you have in other parts of the code. Also, does any of your print()'s work?

Try this:

local part = script.Parent
local function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        print("Car has crashed")
        script.Parent.Parent.Left.on.Value = true
        script.Parent.Parent.Right.on.Value = true
        script.Parent.Parent.Parent.Driveseat.Disabled = true
        if script.Parent.Parent.Parent.DriveSeat.Disabled == true then
            print("DriveSeat has been disabled")
        end
        wait(15)
        script.Parent.Parent.Left.on.Value = true
        script.Parent.Parent.Right.on.Value = true
        script.Parent.Parent.Parent.DriveSeat.Disabled = false
    end
end

As an extra note, I changed this:

if (hit.Parent:findFirstChild("Humanoid") ~= nil) then

to this:

if hit.Parent:FindFirstChild("Humanoid") then

Here I implicitly check if :FindFirstChild returns true, instead of explicitly checking if :findFirstChild does not return false; it’s simpler to understand and is more direct. This is basically the same thing as doing this:

if hit.Parent:FindFirstChild("Humanoid") == true then

The difference is that by doing if __ then it’s, again, “implicitly” checking if it’s true; consider it a perk of the Lua language!

And from what I understand, :findFirstChild is a deprecated function. On the other hand, using a capital F at the beginning like :FindFirstChild is the more accepted and “proper” way of using this.

Let me know how it goes, and what does and does not print.

1 Like

thank you!
I tested the script and it works fine, and the print parts works

Hey, no problem. It would be appreciated if you’d mark the post that worked with the “solution” button. If my post did not work, however, I’m still happy to help out with this problem.

Have a good week!