Attempt to index nil with 'Points'

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Change text to = a points value
  2. What is the issue? Include screenshots / videos if possible!
    Workspace.CurrentFloor.Scoreboard.ScoreboardUI.BG.ListLayout.Example.Info.Points.Script:8: attempt to index nil with ‘Points’ - Server - Script:8
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Devfourms

image

local Players = game:GetService("Players")

local playerName = script.Parent.Parent.PlayerName

for i, player in Players:GetPlayers() do
	while true do
		task.wait()
		if script.Parent.Parent.Parent.Parent.Parent.Parent.Players:FindFirstChild(playerName):FindFirstChild("Points") then
			script.Parent.Text = tostring(script.Parent.Parent.Parent.Parent.Parent.Parent.Players:FindFirstChild(playerName).Points.Value)
		else
			warn("nope, fix me")
		end
	end
end

Yes im aware the code is horrific, im trying to get the code to work before i improve on how it looks

This will definitely give me nightmares…


Maybe this will work?

local playerName = script.Parent.Parent.PlayerName
while task.wait() do
	local playerB = game:GetService("Players"):FindFirstChild(playerName)
	local Points = (playerB and playerB:FindFirstChild("Points"))
	if Points then
		script.Parent.Text = Points.Value
	else
		warn("nope, fix me")
	end
end

is this a server or client script


I should be able to fix this but if not im gonna explode

server script

rtyrtyrtyrtfutygituyguiyuhrds

Maybe it is better to send the complete hierarchy, that is, everything that the model has: Points, PlayerName, this script, etc.

and PlayerName is a value that changes?

1 Like

image

forgot about that mb

I’d recommend moving the script further up in the hierarchy to simplify the script for debugging.

Just to check, does ExamplePlayer get changed to actual player names?

yes, i have a main script:

local Players = game:GetService("Players")

local UI = script.Parent

local ListLayoutFrame = UI.BG:FindFirstChild("ListLayout")
local PlayerExample = UI:FindFirstChild("Players"):FindFirstChild("ExamplePlayer")
local ScoreboardExample = ListLayoutFrame.Example

ScoreboardExample.Visible = false

task.wait(1)

for i, player in Players:GetPlayers() do
	local newPlayerExample = PlayerExample:Clone()
	newPlayerExample.Name = player.Name
	newPlayerExample.Value = player.Name
	newPlayerExample.Parent = UI.Players
	
	local newScoreboardExample = ScoreboardExample:Clone()
	newScoreboardExample.Name = player.DisplayName
	newScoreboardExample.Parent = ListLayoutFrame
	newScoreboardExample.Info.PlayerName.Text = player.DisplayName
	newScoreboardExample.ImageBG.PlayerImage.Image = Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	
	newScoreboardExample.Visible = true
end

task.wait(script.Parent.Parent.Parent.FloorTime.Value - 10)

-- Announce Winners [1ST, 2ND, 3RD]

it clones for each player ingame and changes all the info. I might update the points text in the main code.

Why don’t you just put a Points value inside the actual player instance?

I could try that. I’ll see about adding the code into the main script and then if that doesnt work i will try this method.

1 Like

Sorry, got sidetracked while I wrote this so some of it’s been covered.
Your while true loop never ends so it’s only seeing the first player, not all of them.
Print things like player after setting it to see if it matches what you expect it to.
Players is a service so don’t go through all that Parent.Parent stuff. You may just have one too many or to few .Parents in your code.
If you print your variables instead of just ‘nope didn’t work’ it’ll help you troubleshoot.

My method and this one didnt work at all :frowning: Same error so that sucks alot.