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

Character a nil value?

So what I am trying to do here is load a players 'Body Colors' using a Int value, It all works apart from line 6, it gives this error code out:

error code: Workspace.Game.Player_Edit.Player_Config.Player_Importer:6: attempt to index field 'Character' (a nil value)

game.Players.PlayerAdded:connect(function(player)
	local Name = player.Name
	local Player_Configs = player:WaitForChild("Player_Configs")
	local Skin_Tone = Player_Configs.Skin_Tone.Value
	local Copy = workspace.Game.Player_Edit.Player_Config.Skin_Tone:FindFirstChild(Skin_Tone)["Body Colors"]:Clone()
	player.Character:WaitForChild("Body Colors"):Destroy()
	Copy.Parent = player.Character
	print("Player Loaded")
end)

I decided to add a wait for 'Character' to see if that would work this is the error this gave: Infinite yield possible on 'Players.PastTests:WaitForChild("Character")'

game.Players.PlayerAdded:connect(function(player)
	local Name = player.Name
	local Player_Configs = player:WaitForChild("Player_Configs")
	local Skin_Tone = Player_Configs.Skin_Tone.Value
	local Char = player:WaitForChild("Character")
	local Copy = workspace.Game.Player_Edit.Player_Config.Skin_Tone:FindFirstChild(Skin_Tone)["Body Colors"]:Clone()
	Char:WaitForChild("Body Colors"):Destroy()
	Char = player.Character
	print("Player Loaded")
end)

1 answer

✓ Accepted answer

Remember, the :connect is deprecated use :Connect

Try to add player.CharacterAdded

Here is a example:

game.Players.PlayerAdded:Connect(function(plr)
	print("Player added")
	plr.CharacterAdded:Connect(function(char)
		print("Char added!")
	end)
end)

You can see more here: Wiki - CharacterAdded

Here is your fixed script:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
	    local Name = player.Name
	    local Player_Configs = player:WaitForChild("Player_Configs")
	    local Skin_Tone = Player_Configs.Skin_Tone.Value
	    local Copy = game.Workspace.Game.Player_Edit.Player_Config.Skin_Tone:FindFirstChild(Skin_Tone)["Body Colors"]:Clone()
	    char:WaitForChild("Body Colors"):Destroy()
	    Copy.Parent = char
	end)
end)

Hope it helped :D

Errors? tell-me on comments.

7 comments

0

Did you forget to change :connect() to :Connect() on line 1 of the fixed script?

0

Oh, thanks for warn

0

Ok, so it seems to be working fine thank you, but i'm now just having trouble getting my Data Store to work, So many problems appear out of no where

0

What is errors in your data store?

0

Ok so i figured it out, I was editing the Value of the 'Skin_Tone' Via a Local script in a GUI but OBVIOUSLY that means the server script isnt seeing the change, how would i change the value with a gui that a local script can see? events?

0

use RemoteEvents, if you need help with RemoteEvent create another question. but you can see here of RemoteEvents: https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

0

Ok thank you for the continued support ill will look into it!

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