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)
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)
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);
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)
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,
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
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
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.