ServerScriptService.PlayerAdded:5: attempt to index field 'Character' (a nil value)

The error is

ServerScriptService.PlayerAdded:5: attempt to index field ‘Character’ (a nil value)

Here is the code : local DataStore2 = require(game.ServerStorage.MODULES.DataStore2)

game.Players.PlayerAdded:Connect(function(plr)
local stageDataStore = DataStore2(“StageBETA”, plr)
plr.Character:SetPrimaryPartCFrame(game.Workspace.Stages .. stageDataStore:Get())
end)

edit: it’s using datastore2

1 Like

The character and the Player are added at different times, the character being added after the player, which means you would have to use a CharacterAdded event nested in the PlayerAdded Event

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        --code
    end)
end)
2 Likes

Try plr.CharacterAdded instead of plr.Character

Yeah but i’m going to be using 2 character added events.

pardon? why would you need to do that

Why not put whatever you’re putting in the second event in the first?

You have to wait for the character to load before trying to use it.

You wont need 2 character added events because when one is completed the character has loaded.

2 Likes

k, now it says this after making it into this code : 12:04:30.513 - ServerScriptService.PlayerAdded:6: attempt to concatenate field ‘Stages’ (a userdata value)

code:local DataStore2 = require(game.ServerStorage.MODULES.DataStore2)

game.Players.PlayerAdded:Connect(function(plr)
local stageDataStore = DataStore2(“StageBETA”, plr)
plr.CharacterAdded:Connect(function(char)
char:SetPrimaryPartCFrame(game.Workspace.Stages … stageDataStore:Get())
end)
end)

Stages is an object, if you want to concatenate a value, it would have to either be a number or a string

try using Stages.Value

1 Like

You mean stageDataStore:Get().Value???

He means your trying to join an Object with the stage data store but you can’t concatenate an object

Try char:SetPrimaryPartCFrame(game.Workspace.Stages:FindFirstChild(stageDataStore:Get()).Position)
(Although I am a bit confused on what stageDataStore will be equal to.)

stageDataStore is equal to DataStore2 of the player.

how would I make that object into a string?

So will stageDataStore be a stage spawn or a position?

its a value stored inside of a player using datastore 2. The script is supposed to find the stage inside of the “Stages” folder which is correspondent to the players stage value and then will teleport the player to that position whenever the character is added.

char:SetPrimaryPartCFrame(game.Workspace.Stages:FindFirstChild(stageDataStore:Get()).CFrame) is what you want to do because you need to firstly find the stage from the string value saved as data and you can’t do … to join it you must use FindFirstChild or []

ok now I did this

local DataStore2 = require(game.ServerStorage.MODULES.DataStore2)

game.Players.PlayerAdded:Connect(function(plr)
local stageDataStore = DataStore2(“StageBETA”, plr)
plr.CharacterAdded:Connect(function(char)
char:SetPrimaryPartCFrame(game.Workspace.Stages:FindFirstChild(stageDataStore:Get()).CFrame)
end)
end)

and it says argument 1 is missing or nil.

Check if the DataStore2 module is inside the ServerStorage MODULES

Yeah it is. The datastore works but this doesn’t

We’ve done this but now hes experiencing other problems.

1 Like

Which line does it say this at sorry?