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

Attempt to index nil with 'GirlClothes1'  -  Server  -  Why is it giving me this warning?

Hi. I am working on a character customizer and I need it to save and because I can't find an easier way, I decided to go with making a leaderstat value for each clothing and accessory. Now, the point saves and everything but the problem is that the script in which it checks if you have a point and if you do it gives you clothes, keeps coming out with an error. The script is in serverscriptservice. Code in the script:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " joined the game!")
	
	local stats = player:findFirstChild("leaderstats")
	local Lvl = stats.GirlClothes1

	if stats ~= nil and Lvl.Value >= mlvl then

		print("This player has the green dress!")
		AddUniform(player)
end

end)

The error:

  14:33:33.150 ServerScriptService.Main:60: attempt to index nil with 'GirlClothes1'  -  Server  -  Main:60

I don't understand the warning itself, which is probably why I am having trouble. Thank you!

1 answer

✓ Accepted answer

it means it doesnt exist yet, try adding

player.CharacterAdded:Connect(function(char)

wait()

--everything else

before setting the variables, because chances are, the players stats havent loaded in yet. This is all i can see in the current code you have posted.

i hope this helps :3

2 comments

0

Hello, thank you for responding! Now the error doesn't show up anymore, thank you! Now I just have to figure out why the code isn't doing anything, lol.

1

glad i could somewhat help :)

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