I'm Having Trouble With Instances

I made a leaderstat instance for a obby game, and I want to find a way to identify it:

function PlayerAdded(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = player
    local Stage = Instance.new("NumberValue")
    Stage.Parent = leaderstats
end

how do i Identify the player?
Please, All Answers Help. Thank you.

2 Likes
game.Players.PlayerAdded:Connect(function(player)
      local leaderstats = Instance.new("Folder",player)
    leaderstats.Parent = player
    local Stage = Instance.new("NumberValue",leaderstats)
    Stage.Parent = leaderstats
end)
1 Like

What do you mean by identify the player, but I do know how to identify the new instance, use the Name property

function PlayerAdded(player)
    local leaderstats = Instance.new("Folder") -- Creates the instance with the classname, also don't use the second parameter, as to my knowledge, it is deprecated
    leaderstats.Name = "leaderstats" -- player.leaderstats
    leaderstats.Parent = player -- always set the parent at the end of initializing, so that all relevant data is filled out
    local Stage = Instance.new("NumberValue") -- Creates the instance with the classname, also don't use the second parameter, as to my knowledge, it is deprecated
    Stage.Name = "Stage" -- player.leaderstats.Stage
    Stage.Value = 0 -- or any default value
    Stage.Parent = leaderstats -- always set the parent at the end of initializing, so that all relevant data is filled out
end
1 Like

@GuySalami, I’m Wanting to Identify leaderstats outside of that script, and in another script.

1 Like

Use player:WaitForChild(leaderstats), but make sure that you assign the name like in my code snippet.

1 Like

@GuySalami, It dosen’t work, but thank you

1 Like

Find leaderstats in any other script:

local Player = ... --Define on your own
local leaderstats = Player:WaitForChild("leaderstats")

Can you send me the code or the error message, because using the Name property and using the WaitForChild method won’t fail.

1 Like