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

Vector3.new and Key issue?

Ive got a script which moves a brick left and right and forward and backwards. When I hold "J" it smoothly continues right, same when i press "G" it smoothly goes left. "Y" and "H" doesnt move forward and backward smoothly. Im not sure why, also I have no errors. The functions are located at the bottom

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local y,g,h,j = 0,0,0,0
Mouse.KeyDown:connect(function(Key)
	print("cheese")
	if Key == "j" then
		game.Workspace.CameraBlock.Position = game.Workspace.CameraBlock.Position + Vector3.new(1,0,0)
		j = 1
		keyholdJ()
	elseif Key == "g" then
		game.Workspace.CameraBlock.Position = game.Workspace.CameraBlock.Position + Vector3.new(-1,0,0)
		g = 1
		keyholdG()
	elseif Key == "y" then
		game.Workspace.CameraBlock.Position = game.Workspace.CameraBlock.Position + Vector3.new(0,0,-1)
		h = 1
		keyholdY()
	elseif Key == "h" then
		game.Workspace.CameraBlock.Position = game.Workspace.CameraBlock.Position + Vector3.new(0,0,1)
		y = 1
		keyholdH()
	end
end)

Mouse.KeyUp:connect(function(Key)
	print("cheese")
	if Key == "j" then
		j = 0
	elseif Key == "g" then
		g = 0
	elseif Key == "y" then
		h = 0
	elseif Key == "h" then
		y = 0
	end
end)

--functions of holding down

function keyholdJ()
	while j == 1 do
		game.Workspace.CameraBlock.Position = game.Workspace.CameraBlock.Position + Vector3.new(1,0,0)
		wait(0.01)
	end
end

function keyholdG()
	while g == 1 do
		game.Workspace.CameraBlock.Position = game.Workspace.CameraBlock.Position + Vector3.new(-1,0,0)
		wait(0.01)
	end
end

function keyholdH()
	while h == 1 do
		game.Workspace.CameraBlock.Position = game.Workspace.CameraBlock.Position + Vector3.new(0,0,-1)
		wait(0.01)
	end
end

function keyholdY()
	while y == 1 do
		game.Workspace.CameraBlock.Position = game.Workspace.CameraBlock.Position + Vector3.new(0,0,1)
		wait(0.01)
	end
end

1 answer

✓ Accepted answer

You mixed up Y and H.

elseif Key == "y" then
    game.Workspace.CameraBlock.Position = game.Workspace.CameraBlock.Position + Vector3.new(0,0,-1)
    y = 1
    keyholdY()
elseif Key == "h" then
    game.Workspace.CameraBlock.Position = game.Workspace.CameraBlock.Position + Vector3.new(0,0,1)
    h = 1
    keyholdH()
end

1 comment

0

Thanks! Im not sure how I managed that xD

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