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

Cars don't tween correctly?

Asked by 3 years ago

Local script in PlayerGui

--Settings:
 tweenService = game:GetService("TweenService")
 tweenTime = 4 --default speed 
 easingStyle = Enum.EasingStyle.Linear
 easingDirection = Enum.EasingDirection.InOut
 repeats = math.huge --How many times to repeat the tween (math.huge is the same as infinite)
 reverse = false --Also go in reverse if u want lol
 delayTime = 0 --Delay between each tween if tween repeats


--[[How to use the car system

    1. Replace the Car mesh with the new model mesh.
    2. Under the car mesh place Motor6D weld, primary part 0 for the car mesh, primary part 1 to the hitbox
    3. Move "Goal" to where you want the car to stop driving.   

--]]



--Car

for i,v in pairs (workspace:GetDescendants()) do
    if v.Name == 'Car' then
         model = v
        goalPart = v:WaitForChild("GoalPart")
        if v:FindFirstChild("Speed") then
            tweenTime = v.Speed.Value
        end
        info = TweenInfo.new(tweenTime, easingStyle, easingDirection, repeats, reverse, delayTime)
        local function tweenModel(model, CF)
            local CFrameValue = Instance.new("CFrameValue")
            CFrameValue.Value = model:GetPrimaryPartCFrame()

            CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
                model:SetPrimaryPartCFrame(CFrameValue.Value)
            end)

            local tween = tweenService:Create(CFrameValue, info, {Value = CF})
            tween:Play()

            tween.Completed:Connect(function()
                CFrameValue:Destroy()
            end)
        end

        local success, message = pcall(function()
            tweenModel(model, goalPart.Value.CFrame)
        end)

        if not success then
            print(message)
        end
    end
end


What happens is I set the speed value for one car and the speed for every other car changes even it doesn't even go the default speed.

https://gyazo.com/b3a3533224294e1e805c76ac8fab03a1

Link of the speed values

2
What happens is that you set that one cars speed to tweenTime, and that saves it, so when an other car doesnt have the "Speed" value, it will use the one thats already saved. I suggest putting a tweenTime=4 to the beginning of the loop so it will be 4 unless it has a custom value WoTrox 345 — 3y
0
thanks Ind1v1duals 43 — 3y

Answer this question