Hello,
I am currently making a train game and i want to make a throttle control system by using W to increase the speed and S to decrease the speed.
It is not working and i cant figure it out. I already looked into others topics but i can’t find the solution.
local backleft1 = script.Parent.Parent.Train.Lokomotiv.BackBogie.BackLeft.WheelDown.WheelConstraint
local backleft12 = script.Parent.Parent.Train.Lokomotiv.BackBogie.BackLeft.WheelUp.WheelConstraint
local backright2 = script.Parent.Parent.Train.Lokomotiv.BackBogie.BackRight.WheelDown.WheelConstraint
local backright22 = script.Parent.Parent.Train.Lokomotiv.BackBogie.BackRight.WheelUp.WheelConstraint
local frontleft1 = script.Parent.Parent.Train.Lokomotiv.BackBogie.BackLeft.WheelDown.WheelConstraint
local frontleft12 = script.Parent.Parent.Train.Lokomotiv.BackBogie.BackLeft.WheelUp.WheelConstraint
local frontright2 = script.Parent.Parent.Train.Lokomotiv.BackBogie.BackRight.WheelDown.WheelConstraint
local frontright22 = script.Parent.Parent.Train.Lokomotiv.BackBogie.BackRight.WheelUp.WheelConstraint
local backleft3 = script.Parent.Parent.Train.Lokomotiv.FrontBogie.BackLeft.WheelDown.WheelConstraint
local backleft34 = script.Parent.Parent.Train.Lokomotiv.FrontBogie.BackLeft.WheelUp.WheelConstraint
local backright4 = script.Parent.Parent.Train.Lokomotiv.FrontBogie.BackRight.WheelDown.WheelConstraint
local backright44 = script.Parent.Parent.Train.Lokomotiv.FrontBogie.BackRight.WheelUp.WheelConstraint
local frontleft5 = script.Parent.Parent.Train.Lokomotiv.FrontBogie.BackLeft.WheelDown.WheelConstraint
local frontleft56 = script.Parent.Parent.Train.Lokomotiv.FrontBogie.BackLeft.WheelUp.WheelConstraint
local frontright78 = script.Parent.Parent.Train.Lokomotiv.FrontBogie.BackRight.WheelDown.WheelConstraint
local frontright98 = script.Parent.Parent.Train.Lokomotiv.BackBogie.BackRight.WheelUp.WheelConstraint
local vehicle = script.Parent.Parent.Train.Lokomotiv.VehicleSeat
local speed = vehicle.Throttle
local UserInputService = game:GetService("UserInputService")
local function increaseSpeed()
speed = speed + 1
vehicle:SetPrimaryPartCFrame(vehicle:GetPrimaryPartCFrame() + vehicle:GetPrimaryPart().CFrame.lookVector * speed)
backleft1.AngularVelocity = Vector3.zAxis(speed + 1 )
backleft12.AngularVelocity = Vector3.zAxis(speed + 1 )
backright2.AngularVelocity = Vector3.zAxis(speed + 1 )
backright22.AngularVelocity = Vector3.zAxis(speed + 1 )
frontleft1.AngularVelocity = Vector3.zAxis(speed + 1 )
frontleft12.AngularVelocity = Vector3.zAxis(speed + 1 )
frontright2.AngularVelocity = Vector3.zAxis(speed + 1 )
frontright22.AngularVelocity = Vector3.zAxis(speed + 1 )
backleft3.AngularVelocity = Vector3.zAxis(speed + 1 )
backleft34.AngularVelocity = Vector3.zAxis(speed + 1 )
backright4.AngularVelocity = Vector3.zAxis(speed + 1 )
backright44.AngularVelocity = Vector3.zAxis(speed + 1 )
frontleft5.AngularVelocity = Vector3.zAxis(speed + 1 )
frontleft56.AngularVelocity = Vector3.zAxis(speed + 1 )
frontright78.AngularVelocity = Vector3.zAxis(speed + 1 )
frontright98.AngularVelocity = Vector3.zAxis(speed + 1 )
end
local function decreaseSpeed()
speed = speed - 1
if speed <= 0 then
speed = 0
end
vehicle:SetPrimaryPartCFrame(vehicle:GetPrimaryPartCFrame() + vehicle:GetPrimaryPart().CFrame.lookVector * speed)
backleft1.AngularVelocity = Vector3.zAxis(speed - 1 )
backleft12.AngularVelocity = Vector3.zAxis(speed - 1 )
backright2.AngularVelocity = Vector3.zAxis(speed - 1 )
backright22.AngularVelocity = Vector3.zAxis(speed - 1 )
frontleft1.AngularVelocity = Vector3.zAxis(speed - 1 )
frontleft12.AngularVelocity = Vector3.zAxis(speed - 1 )
frontright2.AngularVelocity = Vector3.zAxis(speed - 1 )
frontright22.AngularVelocity = Vector3.zAxis(speed - 1 )
backleft3.AngularVelocity = Vector3.zAxis(speed - 1 )
backleft34.AngularVelocity = Vector3.zAxis(speed - 1 )
backright4.AngularVelocity = Vector3.zAxis(speed - 1 )
backright44.AngularVelocity = Vector3.zAxis(speed - 1 )
frontleft5.AngularVelocity = Vector3.zAxis(speed - 1 )
frontleft56.AngularVelocity = Vector3.zAxis(speed - 1 )
frontright78.AngularVelocity = Vector3.zAxis(speed - 1 )
frontright98.AngularVelocity = Vector3.zAxis(speed - 1 )
end
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.W then
increaseSpeed()
elseif input.KeyCode == Enum.KeyCode.S then
decreaseSpeed()
end
end
end)
When i run the game and enter the vehicle, by pressing W or S it does nothing. And the console doesn’t show anything too.
What is wrong with my script ?
I am available for more details.
Thanks for reading.