Am I blind or is this a Roblox bug?

But I do in all of these?
characters

1 Like

How so? Is the leftMouse variable already set to true before the player does anything?

1 Like

No, are you proposing this change?

function leftOn()
	local direction = "Left"
	
	left.MouseButton1Down:Connect(function()
		leftMouse = true
		while leftMouse == true do
		game.ReplicatedStorage.CarThrottle:FireServer(direction, leftMouse)
		task.wait()
	end	
	end)
end
function leftOn()
	local direction = "Left"
	
	left.MouseButton1Down:Connect(function()
		leftMouse = true	
	end)
    while leftMouse == true do
		game.ReplicatedStorage.CarThrottle:FireServer(direction, leftMouse)
		task.wait()
	end
end

something like this?

function leftOn()
	local direction = "Left"
	local leftMouse = nil

	left.MouseButton1Down:Connect(function()
		leftMouse = true
	end)

       left.MouseButton1Up:Connect(function()
               leftMouse = false
       end)

while leftMouse == true do
			game.ReplicatedStorage.CarThrottle:FireServer(direction, leftMouse)
			task.wait()
		end	

sorry, I forgot a few ends (replying to my reply above)

Oh I already have one for it, and it still doesn’t work

function leftOff()
	local direction = "Left"
	
	left.InputEnded:Connect(function()
		leftMouse = false
		game.ReplicatedStorage.CarThrottle:FireServer(direction, leftMouse)
	end)
	
	left.InputChanged:Connect(function(input)
		if input.UserInputState == Enum.UserInputState.Cancel then
			leftMouse = false
			game.ReplicatedStorage.CarThrottle:FireServer(direction, leftMouse)
		end
	end)
	
	left.MouseButton1Up:Connect(function()
		leftMouse = false
		game.ReplicatedStorage.CarThrottle:FireServer(direction, leftMouse)
	end)
	
	left.TouchTap:Connect(function()
		leftMouse = true
		game.ReplicatedStorage.CarThrottle:FireServer(direction, leftMouse)
		task.wait()
		leftMouse = false
		game.ReplicatedStorage.CarThrottle:FireServer(direction, leftMouse)
		wait()
		leftMouse = false
		game.ReplicatedStorage.CarThrottle:FireServer(direction, leftMouse)
	end)
end	

leftMouse is a global variable

Yeah, but leave the MouseButton1Down and while loop outside the function

Ok, I see what you are saying, but how would it make a difference if the leftMouse = false won’t fire? I’ll still try it though.

take all the functions inside leftOff() outside of it

1 Like

it fires because it’s in its own thread now. it won’t wait for others to finish to run

1 Like

I have to put them in there though because then the left variable destroy and won’t fire again when a player resets.

1 Like

oh, so the script doesn’t reset, but the UI does?

1 Like

? when a player resets, all code is cloned and reset-ed as well

1 Like

Correct

Characters Characters Characters

1 Like

No, the script is in the playerscripts, so it doesn’t reset, however when a player respawns then the UI resets. I can try changing this, but I don’t think it would make a difference.

1 Like

Oh, ok then. I suggest, if you can, put the script inside the UI, or just put the while loop outside the function that way at least that won’t cause much of an issue.

1 Like

put the script into player GUI. It needs to always respawn with GUI (since it’s manipulating GUI).
otherwise, you can clone it to player gui?

doing so would solve many inconveniences

1 Like

Actually, just re-assign the variable when the function is called. I’ve had that issue occur many times before. But still, put the loop outside the function.

1 Like

Ok sure no problem, I will also say, that these are all fired when the UI is reset so there isn’t any waiting, so putting outside wouldn’t really change anything from that perspective
image

1 Like

Yes that is what I do

1 Like