Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My script to move a car works, but only once?..

Everything works in my script, the player presses W and the car moves, then I let go of W and it stops. But it only works once, I press W then let go, it works then after I press W for the second time after I let go, and nothing works....


wait(0.1)

local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Car = game.Workspace:FindFirstChild(""..Plr.Name.."'s_Car")
local Speed = 1000000

WIsDown = false

Mouse.KeyDown:connect(function(Key)
	if Key == "w" then
		if WIsDown == false then
			WIsDown = true
			local Force = Instance.new("BodyForce")
			Force.Parent = Car.Hitbox
			Force.force = Car.Hitbox.CFrame.lookVector * Speed
			Force.Name = "WForce"
		end
	end
end)

Mouse.KeyUp:connect(function(Key)
	if Key == "w" then
		if WIsDown == true then
			Car.Hitbox.WForce:Destroy()
		end
	end
end)

It's in a local script and output says: 10:38:16.793 - WForce is not a valid member of Part 10:38:16.794 - Script 'Players.Player.PlayerGui.WScript', Line 26

1 answer

✓ Accepted answer

You never added a WIsDown = false

on line 17 press enter and put WIsDown = false

2 comments

0

I didn't notice that, lol. ty

0

No problem c:

This discussion is preserved as it was. New answers, comments, and votes are closed.