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)
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.