Attempt to index nil with 'Position' error

These position errors should occur when the world falls out :face_with_monocle:

local ImageLabel = script.Parent

local PrimaryPart = game:GetService(“Humanoid”)
local Players = game:GetService(“Players”)
local Player = Players.LocalPlayer
local PlayerGui = Player:FindFirstChild(“PlayerGui”)

if Player:FindFirstChild(“PlayerGui”) then
while wait() do
local ImageLabel = PlayerGui.HeightGui.Frame:FindFirstChild(“ImageLabel”)
local Character = game:GetService(“Workspace”)[Player.Name]
local PrimaryPart = Character:FindFirstChild(“LowerTorso”)
local Height = math.ceil(PrimaryPart.Position.Y)
ImageLabel.Position = UDim2.new(-1.6, 0,0.735, 0 - Height / 3,0)
wait(0)
end
end

A few things I don’t understand

  • YOu made a ImageLabel variable already and are trying to get it again?
  • You’re trying to get a Humanoid Service?
  • You dont need to get the character from the loop if the ScreenGui has ResetOnSpawn Enabled

I think this would e a better approach, make sure the ScreenGui this thing is in has ResetOnSpawn enabled!

local ImageLabel = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()
local PrimaryPart = Character:WaitForChild("LowerTorso")

while true do
	local Height = math.ceil(PrimaryPart.Position.Y)
	ImageLabel.Position = UDim2.new(-1.6, 0,0.735, 0 - Height / 3)
	wait()
end

It should be free of errors hopefully as the only thing in that loop is just referencing the Y position of the LowerTorso and updating the ImageLabel. The only way it will error is if this script is in not in the ImageLabel

1 Like
local ImageLabel = script.Parent

local PrimaryPart = game:GetService(“Humanoid”)
local Players = game:GetService(“Players”)
local Player = Players.LocalPlayer
local PlayerGui = Player:FindFirstChild(“PlayerGui”)

if Player:FindFirstChild(“PlayerGui”) then
   while wait() do
      local ImageLabel = PlayerGui.HeightGui.Frame:FindFirstChild(“ImageLabel”)
      local Character = game:GetService(“Workspace”)[Player.Name]
      local PrimaryPart = Character:FindFirstChild(“LowerTorso”)
      local Height = math.ceil(PrimaryPart.Position.Y)
      ImageLabel.Position = UDim2.new(-1.6, 0,0.735, 0 - Height / 3,0)
      wait(0)
   end
end

Code block please, the error here is that there are too many values in the Position parameters. So you would need to have something like this: Udim2.new(-1.6, (0 - Height / 3), 0) Something like this however I’m not to sure what going on there.

To understand this script
I need your answer
Is this script correct?

local Character = game : GetService ( “Workspace”) [Player.Name]

Change the script :arrows_counterclockwise:

local Character = Player.Character or Player.CharacterAdded:Wait()

Real script :white_check_mark:

1 Like