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

Despite no errors in output, camera position dosent change. How do i fix this?

This is a Localscript inside a TextBox inside a Frame Inside a GUI inside a Folder inside starter GUI. This script shows no errors in output when clicked, and no errors in output in general. I don't get why this isnt working. Please help!

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer

--Camera

repeat wait() until Player.Character
Camera.CameraType = "Scriptable"
Camera.CFrame = game.Workspace.CamPos1.CFrame
--Left Door

function click()
Camera.CFrame = game.Workspace.RDoorView.CFrame
script.Parent.MouseButton1Down:connect(click)
	end



2 answers

Okay, so when you create a function, you create it usually with the intent of using it in multiple lines throughout the script, typically. You want to fire the click() function when the event MouseButton1Down is triggered, right? So, you would want to call the function you had written earlier called click() when the event MouseButton1Down is fired. So you would write it like this:

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer

--Camera

repeat wait() until Player.Character
Camera.CameraType = "Scriptable"
Camera.CFrame = game.Workspace.CamPos1.CFrame
--Left Door

function click()
Camera.CFrame = game.Workspace.RDoorView.CFrame
end

script.Parent.MouseButton1Down:connect(function()
	click();
end)

I hope this helped :)

2 comments

0

Your setting the parameter of the function inside MouseButton1Down to "click," but your trying to call the function that has the same name.

0

I forgot to change it but I edited it out just now. Make sure you refresh before posting a comment but thanks lol

You are going to want to connect your event outside of the function that it will be calling, otherwise, well it will never be able to run.

script.Parent.MouseButton1Down:Connect(function()
	Camera.CFrame = workspace.RDoorView.CFrame
end)

Here I end up actually creating a new function instead of calling one that's already created. This is a lot simpler and ends up looking better.

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