Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Character a nil value?

Asked by
PastDays 108
5 years ago
Edited 5 years ago

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

Log in to vote
1
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
Did you forget to change :connect() to :Connect() on line 1 of the fixed script? LoganboyInCO 150 — 5y
0
Oh, thanks for warn yHasteeD 1819 — 5y
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 PastDays 108 — 5y
0
What is errors in your data store? yHasteeD 1819 — 5y
View all comments (3 more)
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? PastDays 108 — 5y
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 yHasteeD 1819 — 5y
0
Ok thank you for the continued support ill will look into it! PastDays 108 — 5y
Ad

Answer this question