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

My LocalScript only partially works (Camera)?

When a player clicks a button on a GUI, he is supposed to be respawned and his camera is meant to go back to his character (I have an intro where it manipulates the camera).

The player being "respawned" (LoadCharacter()) works, however, the camera does not go back to the player's character?

script.Parent.MouseButton1Click:connect(function()
	
	local plr = game.Players.LocalPlayer
	plr:LoadCharacter()	
	
    plr.CharacterAdded:connect(function()
        game.Workspace.CurrentCamera.CameraSubject = plr.Character.Humanoid
		game.Workspace.CurrentCamera.CameraType = "Custom"
    end)
end)

1 comment

0

Try to set the CameraType before CameraSubject ?

1 answer

Take the second function out of the first.

Your code isn't working because you have an unnecessary embedded function. Your code should look like this,

local plr = game.Players.LocalPlayer--Moving variables to the top causes less micro lag.

script.Parent.MouseButton1Down:connect(function()--Using MouseButtonOneDown is better in my opinion.
    plr:LoadCharacter() 
end)

plr.CharacterAdded:connect(function()
    game.Workspace.CurrentCamera.CameraSubject = plr.Character.Humanoid
    game.Workspace.CurrentCamera.CameraType = "Custom"
end)

That's all. Good Luck!

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