Hello!
I’m trying to make a script on where the train speed is zero, the passengers start to spawn from the coaches.
My script:
local Spawnlocation = script.Parent
local Passenger = game.ReplicatedStorage.Passenger
local Speed = script.Parent.Parent.Parent.Parent.SpeedControl.SpeedScript.Speed.Value
local counter = 0
local Amount = math.random(1,10)
if counter < Amount then
local NewPassanger = Passenger:Clone()
NewPassanger.Parent = workspace
NewPassanger:SetPrimaryPartCFrame(Spawnlocation.CFrame)
counter = counter + 1
print(counter)
end
end
The script works fine, all i need is something to detect the train speed value hitting 0 and then the passengers will start to spawn.
Thanks,
Ruben
(P.S. Sorry if the script may looks a bit messy, I’m quite new to scripting with lua and I’m slowly trying to get the hang of it. )
local Spawnlocation = script.Parent
local Passenger = game.ReplicatedStorage.Passenger
local Speed = script.Parent.Parent.Parent.Parent.SpeedControl.SpeedScript.Speed
local counter = 0
local Amount = math.random(1,10)
local function SpawnPassengers()
if Speed.Value <= 0 and counter < Amount then
for Count = 1, Amount - counter do
local NewPassenger = Passenger:Clone()
NewPassenger.Parent = workspace
NewPassenger:SetPrimaryPartCFrame(Spawnlocation.CFrame)
counter = counter + 1
print(counter)
end
end
end
Speed:GetPropertyChangedSignal("Value"):Connect(SpawnPassengers)
local Spawnlocation = script.Parent
local Passenger = game.ReplicatedStorage.Passenger
local SpeedScript = script.Parent.Parent.Parent.Parent.SpeedControl.SpeedScript
local counter = 0
local Amount = math.random(1, 10)
local function spawnPassengers()
while counter < Amount do
local NewPassenger = Passenger:Clone()
NewPassenger.Parent = workspace
NewPassenger:SetPrimaryPartCFrame(Spawnlocation.CFrame)
counter = counter + 1
print(counter)
end
end
SpeedScript.Speed.Changed:Connect(function(newSpeed)
if newSpeed == 0 then
spawnPassengers()
end
end)