Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My LocalScript only partially works (Camera)?

Asked by 8 years ago

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)
0
Try to set the CameraType before CameraSubject ? Spectrobz 140 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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!

Ad

Answer this question