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

Using userinput the make the camera type custom?

local UserInput = game:GetService("UserInputService")

local function InputBegan(input, gameProcessed)
	if input == Enum.UserInputType.MouseButton1 then
		Camera.CameraType = Enum.CameraType.Custom
	end
end

UserInput.InputBegan:Connect(InputBegan)

Using userinput the make the camera type custom? Made this little script but it does not seem to put my camera back to normal after playing a cutsence? Also how can i use userinput to make this key spacebar?

2 answers

if you are going for a more simplistic approach then you could always use GetMouse(), which i will use for an example

local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
mouse.Button1Down:Connect(function()
workspace.Camera.CameraType = "Custom" -- you do not need to use enum for a camera type
end)

forgot to include this but please make sure you are only setting camera type on the client or it wont work

1 comment

0

You are using a deprecated method for detecting if the player has clicked there mouse. You are recommended by Roblox to use UserInputService!

UserInputType

Read about UserInputService first here, InputBegan returns input and gameProcessedEvent. input in your case is not UserInputType but it's just the input Instance. All you have to do is change input == Enum.UserInput.... to input.UserInputType == Enum.UserInput... and it should work.

local UserInput = game:GetService("UserInputService")

local function InputBegan(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
	...

Spacebar and other keys

To use Keys, you need to use Input.KeyCode which is key that the user pressed. All the key names are here. Space would be 32 or Enum.KeyCode.Space. The reason why you can use number is because 32 is number for Space in Ascii characters, here is an image of ascii characters. Code Example:

local function InputBegan(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.Space then
	...

-- or

local function InputBegan(input, gameProcessed)
	if input.KeyCode == '32' then

Both of these will run when spacebar is clicked.

Sources

UserInputType

KeyCode

InputBegan

UserInputService

Ascii Table

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