- What do you want to achieve? Keep it simple and clear!
I have Bus model which can go from bus stop A to B. I need efficient script to make bus able of moving from bus stop to bus stop and opening its doors.
- What is the issue? Include screenshots / videos if possible!
I’ve tried welding the entire model together because tweening model with primary part is a really good solution. But that made it maybe? impossible to open doors since they have to be welded together with the model.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried making sort of hierarchy system of welds in hopes it would work. I have most of the model welded to primary part and then I have parts of Door welded to primary part of Door which is welded to the primary part of model , sadly when I try to move the primary part of Door it still moves the entire model.
Then I’ve tried disabling the welds for the time of tweening but then doors would fall out of the bus.
I’ve tried to do it without welds, but the model has 250 parts which all would have to be tweened separately, which in higher bus amounts would make the game lag.
I tried looking in DevForums and asking AI, but it didn’t help. This is as far as I’ve gotten.
The bus uses 2 scripts, one inside the Bus Model and module script in replicated storage:
Module Script:
local BusFunctions = {}
local TS = game:GetService("TweenService")
function BusFunctions.MoveBus(BusPrimaryPart:Instance, Finnish:Instance, travelDuration:number)
print("Starting up motors")
print(BusPrimaryPart.Name)
local TweenI = TweenInfo.new(travelDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local tween = TS:Create(BusPrimaryPart, TweenI, {["CFrame"] = Finnish.CFrame})
tween:Play()
tween.Completed:Wait()
print("Bus arrived at crossroad/bus stop")
end
function BusFunctions.OpenAndCloseDoors(PrimaryPart:Instance,BackDoor:Model, DriverDoor:Model, DoorOpenedTime:number)
local BDLeft = BackDoor.LeftDoor
local BDRight = BackDoor.RightDoor
local DDLeft = DriverDoor.LeftDoor
local DDRight = DriverDoor.RightDoor
local BDLeftCFrame = BDLeft.PrimaryPart.CFrame
local BDRightCFrame = BDRight.PrimaryPart.CFrame
local DDLeftCFrame = DDLeft.PrimaryPart.CFrame
local DDRightCFrame = DDRight.PrimaryPart.CFrame
local Ti = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
TS:Create(BDLeft.PrimaryPart, Ti, {["CFrame"] = (BDLeftCFrame - Vector3.new(0.668, 0, 0.845)) * CFrame.Angles(0, math.rad(90),0); ["Anchored"] = true}):Play()
TS:Create(DDLeft.PrimaryPart, Ti, {["CFrame"] = (DDLeftCFrame - Vector3.new(0.668, 0, 0.845)) * CFrame.Angles(0, math.rad(90),0); ["Anchored"] = true}):Play()
TS:Create(BDRight.PrimaryPart, Ti, {["CFrame"] = (BDRightCFrame - Vector3.new(-0.73, 0, 0.685)) * CFrame.Angles(0,math.rad(-90),0); ["Anchored"] = true}):Play()
TS:Create(DDRight.PrimaryPart, Ti, {["CFrame"] = (DDRightCFrame - Vector3.new(-0.73, 0, 0.685)) * CFrame.Angles(0,math.rad(-90),0); ["Anchored"] = true}):Play()
wait(3)
print("Doors have been opened")
wait(DoorOpenedTime)
TS:Create(BDLeft.PrimaryPart, Ti, {["CFrame"] = BDLeftCFrame; ["Anchored"] = false}):Play()
TS:Create(DDLeft.PrimaryPart, Ti, {["CFrame"] = DDLeftCFrame; ["Anchored"] = false}):Play()
TS:Create(BDRight.PrimaryPart, Ti, {["CFrame"] = BDRightCFrame; ["Anchored"] = false}):Play()
TS:Create(DDRight.PrimaryPart, Ti, {["CFrame"] = DDRightCFrame; ["Anchored"] = false}):Play()
wait(3)
print("Doors have been closed")
end
return BusFunctions -- I had troubles with making both things happen at least, that's why there's Anchored variables inside the tween goals
Script inside Bus Model:
local BusFunctions = require(game.ReplicatedStorage.BusFunctions)
local BusStopWaitTime = 30 -- in seconds
local TS = game:GetService("TweenService")
local DoorsFolder = script.Parent.Doors
local BackDoor = DoorsFolder.BackDoor
local DriverDoor = DoorsFolder.DriverDoor
BusFunctions.OpenAndCloseDoors(script.Parent.PrimaryPart, BackDoor, DriverDoor, 5)
wait(2)
BusFunctions.MoveBus(script.Parent.PrimaryPart, game.Workspace.Finish, 10)
Does anyone know how to make this work with welds? Or any other reasonable solution?