So I have this script and it is supposed to off set the camera "in other words to shake the screen". Here is the error message:
Players.Player2.PlayerGui.LocalScript:2: attempt to index field 'Character' (a nil value)
Here is the script:
***for i = math.huge, math.huge do game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new(math.random(-2,2),math.random(-2,2),math.random(-2,2)) wait() end game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new(0,0,0)***
I'm in need of help! :D
@ line 2, put game:GetService("Players").LocalPlayer.Character.Humanoid.CameraOffset also, if it says character, Humanoid, or CameraOffset doesnt exist, place a WaitForChild()
The problem is, that a script runs before the character even gets added. So the Character doesn't exist by the time you are running the script. An efficient way to prevent it is to wait until the character loads using game.Players.LocalPlayer.CharacterAdded:Wait()
.
This is how the code will look:
game.Players.LocalPlayer.CharacterAdded:Wait() for i = math.huge, math.huge do game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new(math.random(-2,2),math.random(-2,2),math.random(-2,2)) wait() end game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new(0,0,0)