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

How do I make a model (in specific, a car) lock when you sit in the seat?

Asked by 9 years ago

Like, I'm wondering how I'd lock all of the car when you sit in the driver's seat something like getchildren but I'm still learning, so

(Sorry if the tag isn't what it should be, not sure what this would fall under)

3 answers

Log in to vote
0
Answered by
jakedies 315 Trusted Moderation Voter Administrator Community Moderator
9 years ago

Lock all the parts when someone sits down.

local car = workspace.Car; --You may have to edit this
local seat = car.VehicleSeat; --And this
local children = car:GetChildren();

local lockCar = function(locked)
    for key = 1, #children do
        local value = children[key];
        if value:IsA("BasePart") then
            value.Locked = locked;
        end
    end
end;

seat.ChildAdded:connect(function() lockCar(true); end);
seat.ChildRemoved:connect(function() lockCar(false); end);
Ad
Log in to vote
-1
Answered by
Legojoker 345 Moderation Voter
9 years ago

Every time someone sits down on a seat, a child is added in to Seat. It is called SeatWeld. When they get off, SeatWeld is removed. You will need to fill in some of the userdata where I require it, as I don't know what exactly is where.

local car = -- Guessing it's in workspace somewhere. Just give the userdata here.
local seat = car.Seat -- Guessing seat is in the model car. (PLEASE make the car a model if it isn't already.)

function RunToggle(val) -- Will be called later.
    for i,v in pairs(car:getChildren()) do
        if v:IsA("BasePart") then
            c.Locked = val -- Idk why you want it to be locked, I'm guessing you might mean that the car doors no longer open, in which case you would need to have every brick you want closed in your car named Door.
            if v.Name == "Door" then
                v.CanCollide = val
            end
        end
    end
end

seat.ChildAdded:connect(function(c)
    if c:IsA("Weld") then
        RunToggle(true)
    end
end)
-- Below is to cancel everything done if the person gets up.
seat.ChildRemoved:connect(function(c)
    if c:IsA("Weld") then
        RunToggle(false)
    end
end)
0
By lock, I mean like have it so it can't be deleted, not having the car doors lock so nobody can get in xD TheFurryFish -5 — 9y
0
Oh ok, well then the door part of the script should work too! Just make sure you name all your doors Door in the car :D. Legojoker 345 — 9y
Log in to vote
-2
Answered by
IcyEvil 260 Moderation Voter
9 years ago

I believe something like this

c = game.Workspace.Car:GetChildren()
if c.Seat == SatDownIn? -- Dont know what the peice of coding is for when you sit down. then
c.Anchored = true
end

Sorry about the SatDownIn part I didnt the peice of coding that would mean that,

Answer this question