Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a road with cars passing on it?(No obstacles or lane switching)

Asked by 2 years ago
Edited 2 years ago

I am kind of new to roblox studio and one thing I have wanted to do is make a working highway. I don't really know much about scripting and I really want to know how to do this. Now if you do know how to make obstacles an extras like that, I am happy to learn. I am not asking for that but if you do know please tell. I would love to know. I looked on YouTube, and every video is fake or outdated. Anyone want to help?

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

I am here to come to your aid.

So, first of all, I have published a model to make this easier.

https://web.roblox.com/library/9123240882/Car-Model

Second of all, lets start scripting!

Add a script in the workspace and name it "CarPassingScript".

Then insert this code inside the script:

local model = workspace.CarModel -- If you change the name of the CarModel in the workspace, you will have to rename this accordingly. Make sure you don't make a spelling mistake!
local car = model.CarPassingBy
local TS = game:GetService("TweenService") -- Using the GetService() function to get TweenService
local TI = TweenInfo.new(4 --[[By using TimeLength it will take 3.7 seconds because of how long the "Running" audio sound is.--]],Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0) -- The properties in here are time, easingStyle, easingDirection, repeatCount, will it reverse (e.g, false) and delay time in that order.

while wait(5) do
    local clone = car:clone() -- Cloning the car is basically duplicating it, self-explanatory.
    clone.Parent = workspace -- We must set the parent or else we won't see it because it doesn't exist.
    print(clone)
    local Tween = TS:Create(clone.Seat,TI,{Position = model.CarPassingByEndPos.Seat.Position})
    -- Okay, let me explain what the tween does. We get the instance (in this case, the car seat), then we get our info (previously elaborated), then we get the position.
    Tween:Play() -- We play the tween.
    Tween.Completed:Connect(function()
        clone:Destroy() -- Destroying the clone
    end)
end

Thank you for (probably) listening.

Ad

Answer this question