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

Why wont the part keep moving when I press E?

Its supposed to be moving one stud every 0.5 seconds but it only moves once when you press e. here's my script.

UserInputService = game:GetService("UserInputService")
local Part = game.Workspace.ColorPartTest
local x = Part.Position.X
local y = Part.Position.Y
local z = Part.Position.Z

local akeypressed = false

UserInputService.InputBegan:Connect(function(input,gameProccessedEvent)
	if input.KeyCode == Enum.KeyCode.E then
		akeypressed = true
		while akeypressed == true do
			wait(0.5)
			Part.Position = Vector3.new(x + 1,y,z)
		end
		
	end
end)

UserInputService.InputEnded:Connect(function(input,gameProccessedEvent)
	if input.KeyCode == Enum.KeyCode.E then
		akeypressed = false
	end
end)

2 answers

✓ Accepted answer

I don't know if this works to you but i think i fixed it

local UserInputService = game:GetService("UserInputService")
local Part = game.Workspace.ColorPartTest
local x = Part.Position.X
local y = Part.Position.Y
local z = Part.Position.Z

local akeypressed = false

UserInputService.InputBegan:Connect(function(input,gameProccessedEvent)
	if input.KeyCode == Enum.KeyCode.E then
		akeypressed = true
		while akeypressed do
			wait(0.5)
			x += 1
			Part.Position = Vector3.new(x,y,z)
		end
	end
end)

UserInputService.InputEnded:Connect(function(input,gameProccessedEvent)
	if input.KeyCode == Enum.KeyCode.E then
		akeypressed = false
	end
end)

1 comment

0

thanks dude

Lines 20 - 24!

Once the keypress ended, it'll change the "akeypressed" value back to false!

Removing line 22 would fix it

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