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

I assign g as the key but when i press other buttons the code still run help?

it might be a stupid error but every time i press a key my camera changes the problem is that i assigned g as the key and for some reason any button i press it runs the code and i'm not sure why here is the code.

buttonPressed = false
mouse = game.Players.LocalPlayer:GetMouse()

mouse.KeyDown:connect(function(key)
	buttonPressed = true 
	if key == "g" then
		end
end)
	
	mouse.KeyUp:connect(function(key)
	buttonPressed = false
	if key == "g" then
	end
	while wait() do
	if buttonPressed then
		local target = workspace.Part
		local camera = workspace.CurrentCamera
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CameraSubject = target
		
		camera.CoordinateFrame = CFrame.new(target.Position)
		*CFrame.new(2.9,4.6,-22)
		*CFrame.Angles(0,-3.1,0)
	else
		game.Workspace.CurrentCamera.CameraSubject = 	game.Players.LocalPlayer.Character.Humanoid
        game.Workspace.CurrentCamera.CameraType = "Custom"
end
	end
	end)
	



1 answer

I see your problem. At lines 12-13, you have the function and then you immediately end it with an end. You should move that end to around line 28.

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