The issue is, how can I make it so where it waits until there is enough players in the script for car/truck to move.
I need the truck to move once enough players. This is already in the truck seats but not care
This question wasn’t posted anywhere and im not experienced with lua in any way.
Script for cars to move
Car = workspace.Truck1
while true do
wait(5) -- Time it takes before the Car leaves
for i = 1,200 do
Car:TranslateBy(Vector3.new(-1,0,0)) -- Goes straight
wait()
end
for i = 1,200 do
Car:TranslateBy(Vector3.new(1,0,0)) -- Goes back
wait()
end
end
Script for the seats in the truck to teleport the players
local seats = workspace.Truck1.Seats
local teleportService = game:GetService("TeleportService")
local num = 0
local playersInSeats = {}
local countdown = false
-- remove the prints if you'd like
local function countDown()
if not countdown then
countdown = true
playersInSeats = {}
for i = 5,1,-1 do -- change the first number to the length of countdown
if num < 1 then break end -- if everyone gets off, reset timer
if num == #seats:GetChildren() then break end -- if seats are full, teleport
wait(1)
end
if num >= 1 then -- change this to minimum number of players
local serverCode = teleportService:ReserveServer(4053973750) -- change game.PlaceId to the place id
for _,seat in pairs(seats:GetChildren()) do
if seat.Occupant then
local plr = game.Players:GetPlayerFromCharacter(seat.Occupant.Parent) -- occupant is the humanoid, hence why
table.insert(playersInSeats,plr)
end
end
teleportService:TeleportToPrivateServer(4053973750,serverCode,playersInSeats) -- change game.PlaceId to the place id
countdown = false
else
countdown = false
end
end
end
for _,seat in pairs(seats:GetChildren()) do
if seat:IsA("Seat") then
seat:GetPropertyChangedSignal("Occupant"):connect(function()
if seat.Occupant ~= nil then
num = num + 1
countDown()
else
num = num - 1
end
end)
end
end
I would like to know how to make is so when there is enough players it changes the wait system to something else or if it isnt alot of players it changes it to something. It would also have the same system as the script above but I dont really know. Help is appreciated, not needed.
This line may be promising, just change it from 1 to the minimum number of players you want before it teleports the players. Lets say you wanted at least 5 players to start, you would simply change the line to look like this: if num >= 5 then -- change this to minimum number of players
Thanks for helping but I dont think thats the solution. I meant that I wanted the truck to move once it reaches that much players not changing the minimum. I am talking about the line
wait(5) – Time it takes before the Car leaves <— I need to edit that so its 5 players not 5 seconds
Delete the top script and replace the bottom script with the following code:
local seats = workspace.Truck1.Seats
local teleportService = game:GetService("TeleportService")
local num = 0
local playersInSeats = {}
local minimumOccupancy = 1 -- the minimum amount of players required to move
local minimumOccupancyFulfilled = false
local minimumOccupancyReached = Instance.new("BindableEvent")
local countdown = false
-- remove the prints if you'd like
local function countDown()
if not countdown then
countdown = true
playersInSeats = {}
for i = 5,1,-1 do -- change the first number to the length of countdown
if num < 1 then break end -- if everyone gets off, reset timer
if num == #seats:GetChildren() then break end -- if seats are full, teleport
wait(1)
end
if num >= minimumOccupancy then -- change this to minimum number of players
local serverCode = teleportService:ReserveServer(4053973750) -- change game.PlaceId to the place id
for _,seat in pairs(seats:GetChildren()) do
if seat.Occupant then
local plr = game.Players:GetPlayerFromCharacter(seat.Occupant.Parent) -- occupant is the humanoid, hence why
table.insert(playersInSeats,plr)
end
end
teleportService:TeleportToPrivateServer(4053973750,serverCode,playersInSeats) -- change game.PlaceId to the place id
countdown = false
else
countdown = false
end
end
end
local function updateOccupancy(occupants)
if occupants >= minimumOccupancy then
minimumOccupancyFulfilled = true
minimumOccupancyReached:Fire()
else
minimumOccupancyFulfilled = false
end
end
for _,seat in pairs(seats:GetChildren()) do
if seat:IsA("Seat") then
seat:GetPropertyChangedSignal("Occupant"):connect(function()
if seat.Occupant ~= nil then
num = num + 1
countDown()
updateOccupancy(num)
else
num = num - 1
updateOccupancy(num)
end
end)
end
end
Car = workspace.Truck1
while true do
if not minimumOccupancyFulfilled then
minimumOccupancyReached.Event:Wait()
end
wait(5) -- Time it takes for the car to leave after minimum occupancy has been reached
for i = 1,200 do
Car:TranslateBy(Vector3.new(-1,0,0)) -- Goes straight
wait()
end
for i = 1,200 do
Car:TranslateBy(Vector3.new(1,0,0)) -- Goes back
wait()
end
end
I haven’t tested this so I’m not 100% sure it would work, but I hope it does so let me know. All you need to do is change the minimumOccupancy variable at the top to your desired value.
Unfortunately, it glitched so like it tp’d me before the vehicle moved and said “failed to teleport” then the vehicle moved then it tp’d me. I think it would be good if u also joined the game yourself.
Thanks for helping as I saw you replying and taking your time, unfortunately, it didnt work.
I’d ask you to try some debugging but you stated that you had absolutely no lua experience so that won’t be possible. It’s difficult to help someone with zero experience without simply doing it for them, which is not the point of this forum. At this point I advise you hire a scripter or someone to complete this project for you; unless someone else sees an issue in the code that may fix your problem, that is your best option. Sorry I wasn’t able to solve your issue.