Sometimes Cars Don't Drive, Sometimes They Fly

So, following from my past post,

I made some coding changes I thought would fix the situation. Instead, it appears it’s made it worse…

I was using the original code in the video, and for some reason, this user was triggering off the following code, even after leaving the car, and it seems that it has something to do with their proximity and my proximity to the car. The following code is run in a local script inside a gui in the player’s guis.

local plr = game.Players.LocalPlayer
local m = plr:GetMouse()
local s = script.Parent.Seat.Value
local t = script.Parent.TextLabel
local UserInputService = game:GetService("UserInputService")

m.KeyDown:connect(function(key)
	if key == "f" then
		if s.Velocity.magnitude > 20 then
			for i = 0, 10, 0.5 do
				local x = 1-(i/10)
				t.Position = UDim2.new(0.5,-400,0,30-(x^2)*200)
				wait()
			end
			wait(2)
			for i = 0, 10, 0.5 do
				local x = i/10
				t.Position = UDim2.new(0.5,-400,0,30-(x^2)*200)
				wait()
			end
		else
			local p = Instance.new("BodyPosition",s)
			p.maxForce = Vector3.new(10000000,10000000,10000000)
			p.Position = s.Position+Vector3.new(0,5,0)
			local g = Instance.new("BodyGyro",p.Parent)
			wait(3)
			p:Destroy()
			g:Destroy()
		end
	end
end)

So is your problem only that the code is executing after you exit the car? Or are you also unsure why the car is rising up in the air?

I’m uncertain why it’s now executing the Flip Code after the person has left the car. When I execute that code, and leave the car, the car falls to the ground. This is a new issue. Aside from that, still no clue why people have a random issue where like 30% of users complain the car is unable to drive (all users on PCs). Idk, just seems like Roblox cars are becoming very wacky.

The variable ‘s’ is assigned to a value within the seat, what value is this?

Also, is anyone pressing F after they exit the car / is there anything preventing them from flipping it if they are not sitting?

S is an object value named Seat, that finds the car’s seat in Workspace when the user gets into the car. The GUI that is holding this script is destroyed when the player leaves the car seat, which is weird how this user experienced their scripts still being called, when it should be destroyed.

This particular bug only showed up when I changed my drive code from this to this. Of which, the drive code doesn’t touch the Flip script that I posted above at all so I have no clue why that would change anything.

Can I see the code thats executed when you leave the seat?

I’ll DM you a whole copy of my cars, so you can see everything going on.

Just checking but you are disconnecting the keybinding when the user exits the car?

Also as a small side note, you shouldn’t really use Mouse.KeyDown anymore as it should really be deprecated. Instead use:

game:GetService("UserInputService").InputBegan:Connect(function(InputObject, GameProcessedEvent)
    if InputObject.KeyCode == Enum.KeyCode.F then
        -- Stuff goes here...
    end
end)

True, lol. That particular code is from a free model that the racing community has been using for a while.
The code I was using via input for driving the car was:

local function WInputBegan(input,gameProcessed) -- W
    if input.UserInputType == Enum.UserInputType.Keyboard then
        while UserInputService:IsKeyDown(Enum.KeyCode.W) == true do
            wait()
            local maxSpeed = seat.Configuration.MaxSpeed.Value
            local torque = seat.Configuration.Torque.Value * 1000
            leftDrive.AngularVelocity = maxSpeed * 1
            rightDrive.AngularVelocity = -maxSpeed * 1
            rightDrive.MotorMaxTorque = torque
            leftDrive.MotorMaxTorque = torque
        end
        leftDrive.AngularVelocity = 0
        rightDrive.AngularVelocity = 0
    end
end

The issue arrives randomly though, after my drive script no longer works for that user. It’s kinda hard to explain. That being said, the script shouldn’t be running once the user leaves the car, because when the user leaves the car, the script gets destroyed, as well as the gui that it’s running in.

You able to send over the model? You can DM or add me on Discord (FracturedSoftware#8159) if you want and then I can take a closer look at it all and get back to you with a fixed version.

1 Like