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

Stage is not a valid member of Folder while referencing leaderstats, why is this happening?

Asked by 4 years ago
Edited 4 years ago

I am making an obby checkpoint system with saves and am running into the following issue

Stage is not a valid member of Folder

here are my code snippets: script in checkpoint part


if humanoid then print(plr.Parent.Name) local player1 = game:GetService("Players"):GetPlayerFromCharacter(workspace[plr.Parent.Name]) print(type(player1)) local spawns = datastoreservice:GetDataStore("spawns") print(player1.userId) spawns:SetAsync(player1.userId, encodeCFrame(player1.Character:WaitForChild("HumanoidRootPart").CFrame)) -- printTable(player1.leaderstats:GetChildren()) game:GetService("Players")[player1.Name].leaderstats["Stage"] = script.Parent.Name end end)

script in serverscriptservice


game:GetService('Players').PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local level = Instance.new("IntValue", leaderstats) level.Name = "Stage" level.Value = 1 print(player.leaderstats.Stage)

Please could someone help as to why this error is being caused as i can see the playername.leaderstats.Stage value in explorer but in the script it cant find it any help would be appreciated Josh Edit: fix code edit 2: only include references to leaderstats

0
http://idownvotedbecau.se/toomuchcode Please don't make us pick through your code line by line to find the issue, post only and ONLY a minimal, complete, and verifiable example. That is, post as little code as you can that can still reproduce the problem, but make sure it's complete, and verifiable being, it would still compile and run, and produce the problem. I will happily remove -1 if you fix programmerHere 371 — 4y
0
sorry its because i dont know whats causing it so i cant identify the bits and im new to lua plzdonthitman 3 — 4y
0
oki fixed it plzdonthitman 3 — 4y
0
Now you have too little. In the first one, there is no humanoid variable. So we don't know the background context. In the second one, you're missing an end for your function literal and a closing ) to close off that :Connect() call. Make sure the code you provide at least compiles. programmerHere 371 — 4y

2 answers

Log in to vote
0
Answered by
0_2k 496 Moderation Voter
4 years ago
Edited 4 years ago

You forgot the WaitForChild incase the instance isn't yet created / loaded in yet. Also try Stage.Value?

-- >> Checkpoint Script
local datastoreservice = game:GetService("DataStoreService")
local spawns = datastoreservice:GetDataStore("spawns")

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")

    if humanoid then
        local player1 = game.Players:GetPlayerFromCharacter(hit.Parent)
        spawns:SetAsync(player1.userId, encodeCFrame(player1.Character:WaitForChild("HumanoidRootPart").CFrame))
--      printTable(player1.leaderstats:GetChildren())
        player1.leaderstats:WaitForChild("Stage") = script.Parent.Name
    end
end)
0
This code doesn't even compile check line 32 in here programmerHere 371 — 4y
0
ok, but it might be something in the server script bcos i pasted in the wrong one plzdonthitman 3 — 4y
0
1) Too much code 2) All the variables is not needed at all, but try this revised version 0_2k 496 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Stage is not a property.

I found the issue. It's this:

game:GetService("Players")[player1.Name].leaderstats["Stage"] = script.Parent.Name

You are treating Stage as like a property, however this fails as it's not a property.

Just append a .Value.

Also this code can severely be cleaned.

First off, why go backwards to game:GetService("Players") only to index it for player1.Name?

This could be simplified to

player1.leaderstats.Stage.Value = script.Parent.Name

Mostly I answered because I wanted to clean up your printTable function.

It can be as simple as...

local function print_table(t)
    print(string.format("{%s}", table.concat(t, ", ")))
end

I would clean up your code, however it's too messy and beyond cleaning. You may need to restructure and rewrite parts of your code base to clean it up.

Answer this question