I’m making a car powered by LinearVelocity forces, and it works, but even if there is no player in it the car moves.
UIS = game:GetService("UserInputService") --Get Input
local Movement = script.Parent.Parent.Parent.Model:WaitForChild("Red")
UIS.InputBegan:Connect(function(input) --Move Keyboard
if script.Parent.Torque ~= 0 and script.Parent.Occupant ~= "" then -- I think this has something to do with it but I'm not a professional
if input.KeyCode == Enum.KeyCode.W then --Forwards
Movement.LinearVelocityF.Enabled = true
Movement.LinearVelocityB.Enabled = false
elseif input.KeyCode == Enum.KeyCode.S then --Backwards
Movement.LinearVelocityF.Enabled = false
Movement.LinearVelocityB.Enabled = true
elseif input.KeyCode == Enum.KeyCode.A then
Movement.AngularVelocityCCW.Enabled = true
Movement.AngularVelocityCW.Enabled = false
elseif input.KeyCode == Enum.KeyCode.D then
Movement.AngularVelocityCCW.Enabled = false
Movement.AngularVelocityCW.Enabled = true
else -- ¯\_(ツ)_/¯ idk the Assistant put this here. It probably does something.
Movement.LinearVelocityF.Enabled = false
Movement.LinearVelocityB.Enabled = false
Movement.AngularVelocityCCW.Enabled = false
Movement.AngularVelocityCW.Enabled = false
end
else
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D then --Stop
Movement.LinearVelocityF.Enabled = false
Movement.LinearVelocityB.Enabled = false
Movement.AngularVelocityCCW.Enabled = false
Movement.AngularVelocityCW.Enabled = false
end
end)
If a player is either in the car or not, the car still moves.