Hello guys, I’m trying to make a system that when a player is seated on a seat and the Owner of the car despawn the car, then the player forced to get out, and all is good at this point, but I have a problem: I need that the script runs only if at least one of the seat is occupated, but I don’t know how to make it, below there’s the script
for i,v in pairs(plrCars[plr]:GetDescendants()) do
if v:IsA("Seat") then
if not v.Name == "VehicleSeat" then
local player = game.Players:GetPlayerFromCharacter(v.Occupant.Parent)
local Character = player.Character
local AnimationTracks = player.Character.Humanoid:GetPlayingAnimationTracks()
for i, v in pairs(AnimationTracks) do
v:Stop()
end
for i,v in pairs(Character:GetDescendants()) do
if v:IsA("BasePart") then
v.Massless = false
end
end
for i,v in pairs(Character:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then
v.Transparency = 0
Character:FindFirstChild("HumanoidRootPart").Transparency = 1
end
end
v.Disabled = true
end
end
end
You can check the changes in each of the seats and turn on this script, if the owner has started the car, then activate it. However, in order to do this, I need to know the location of the scripts and parts in the car.
well the problem is that the script is inside the ServerScriptService, and I have to use this for all the vehicle, this is the reason why I’m using this kind of script to get the seats
for i,v in pairs(plrCars[plr]:GetDescendants()) do
if v:IsA("Seat") then
v:GetPropertyChangedSignal("Occupant"):Connect(function()
if not v.Name == "VehicleSeat" then
local player = game.Players:GetPlayerFromCharacter(v.Occupant.Parent)
local Character = player.Character
local AnimationTracks = player.Character.Humanoid:GetPlayingAnimationTracks()
for i, v in pairs(AnimationTracks) do
v:Stop()
end
for i,v in pairs(Character:GetDescendants()) do
if v:IsA("BasePart") then
v.Massless = false
end
end
for i,v in pairs(Character:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("Decal") then
v.Transparency = 0
Character:FindFirstChild("HumanoidRootPart").Transparency = 1
end
end
v.Disabled = true
end
end
end
end