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

What is wrong with this LocalScript?

I was trying to Manipulate the Camera of a Player, when i made it to get fixed on a part it worked, but there was a problem with fixing it back to the Players Humanoid. This is the Code i used:

local Button = script.Parent

function close()
	if script.Parent.Value.Value == false then
		script.Parent.Value.Value = true
		script.Parent.Parent.Parent.LocalScript.Value.Value = false
		game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Humanoid
		game.Workspace.CurrentCamera.CameraType = "Custom"
	end
end

Button.MouseButton1Click:connect(close)

Magically in Studio is working fine but when i run the code in Roblox Player it does not work, it just stops the camera where it is and does not moves it to the Player

The Developer Console says the following: Players.lehel55.PlayerGui.ScreenGui.Test.Script:9: attempt to index field 'LocalPlayer' (a nil value)

But the Player can be moved using WASD, just the camera is not moving or can't be movable

1 comment

0

Are you certain this is a LocalScript, and not a Script?

1 answer

✓ Accepted answer

The LocalPlayer object does not contain the Humanoid object. However, it does contain Character which contains Humanoid. On line 7, you are trying to reference the Humanoid directly from the LocalPlayer which (as I've stated) does not contain Humanoid. Replace line 7 with:

game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid

I also recommend making Character a variable when working with LocalScripts and Cameras.

4 comments

0

Hey lehel55 if this helped you can accept it as an answer, so that way people know the question is correctly answered.

0

I tested it out how you said but it gave the same error, and the Frame what should disappear after the Camera is on the Humanoid does not disappear, and gives the same error in the console

0

i'm going to post it again but this time the whole script...not just a part (i removed the part what is "useless")

0

I found the problem, but you were right too..

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