#Stage Saving Script Error

182 messages · Page 1 of 1 (latest)

void sedge
#

Hey guys, I wrote a script from a youtube tutorial. It works well but there's a problem: It doesn't save my progress when I leave. In the output, it says "UserID is not a valid member of Player "lewcio_szmulcias"". I'll put the script in the replies, can anyone please help me find the problem? Thanks!

#
local dataStoreService = game:GetService("DataStoreService")
local stageStore = dataStoreService:GetDataStore("PlayerStageDataStore")

function plrToStage(plr)
    repeat wait() until plr.Character.HumanoidRootPart
    
    local stagePart = game.Workspace.Checkpoints:FindFirstChild(tostring(plr.leaderstats.Stage.Value))
    
    plr.Character.HumanoidRootPart.CFrame = stagePart.CFrame + Vector3.new(0,2.5,0)
end

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    
    local stage = Instance.new("IntValue")
    stage.Name = "Stage"
    stage.Parent = leaderstats
    
    local success, errorMsg = pcall(function()
        stage.Value = stageStore:GetAsync(player.UserId)
    end)
    
    if success then
        print("Successfully got".. player.Name.."'s stage data.")
    else
        warn(errorMsg)
    end
    
    if player.Character then
        plrToStage(player)
    end
    
    player.CharacterAdded:Connect(function()
        plrToStage(player)
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errorMsg = pcall(function()
        stageStore:SetAsync(player.UserID,player.leaderstats.Stage.Value)
    end)
    
    if success then
        print("Successfully saved"..player.Name.."'s stage data.")
    else
        warn(errorMsg)
    end
end)

for _, checkpoint in pairs(game.Workspace.Checkpoints:GetChildren()) do
    checkpoint.touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            
            local checkpointNumber = tonumber(checkpoint.Name)
            
            if player.leaderstats.Stage.Value < checkpointNumber then
                player.leaderstats.Stage.Value = checkpointNumber
            end
        end
    end)
end
marble oasis
#

lua is case sensitive

tacit oyster
#

yeah

marble oasis
#

so instead of UserID

tacit oyster
#

typo

marble oasis
#

its UserId

tacit oyster
#

You need UserId not UserID

void sedge
#

Oh

#

Okay

marble oasis
#

lowkey got confused what was wrong and then realized the capital D

void sedge
#

And

#

can you help with 1 more thing

#

@marble oasis

marble oasis
#

yea sure

#

what is it

void sedge
#

How do I reset the progress

#

for a player

#

like to send them back to stage 0

marble oasis
#

is there a button to send them back to stage 0?

void sedge
#

no

marble oasis
#

or do uw ant to do it for everyone

void sedge
#

for

#

wiat what

marble oasis
#

like reset progress for one player or for everyone

void sedge
#

1 player

marble oasis
#

are they able to do it at their own will?

void sedge
#

right now they cant do shit cause i don't know how to script resetting progress

#

also

#

now it says 403: Cannot write to DataStore from studio if API access is not enabled.

marble oasis
#

oh

#

open game settings, go to security and turn on "Enable Studio Access to API Services"

void sedge
#

Okay

marble oasis
#

game settings is in ur home tab btw

void sedge
#

Ik

#

Anyway do you know how to like

#

reset the progress for a chosen player?

marble oasis
#

do u want the player to reset their progress by themselves or u want to reset for them

void sedge
#

uh

#

me for them

marble oasis
#

ok sick u can just lua stageStore:SetAsync(player.UserId, 0)

void sedge
#

where it says userId u put the player's user id?

marble oasis
#

yea replace the player.userid with the users id

void sedge
#

ok and where do i put it

#

in a seperate script or to this script

marble oasis
#

is it a temporary thing?

#

if its temporary then ```lua
local dataStoreService = game:GetService("DataStoreService")
local stageStore = dataStoreService:GetDataStore("PlayerStageDataStore")

stageStore:SetAsync('replace with userid', 0)```
u put this in the F9 console

void sedge
#

into the what

#

also wdym by temporary

marble oasis
#

when u join the game

void sedge
#

Ok

#

And what do you mean temporary

marble oasis
void sedge
#

Do you mean like

#

Yes

#

One time

#

Sol ike

#

theyre at stage 10

#

I reset it

#

theyre at 0

#

and they have to do it again

marble oasis
#

yea

marble oasis
void sedge
#

Yeah so that it doesn't always put them at 0 no matter what stage they're at

void sedge
#

or just (UserId, 0)

marble oasis
void sedge
#

ok but you didn't type it in

#

so it should be:

#
local dataStoreService = game:GetService("DataStoreService")
local stageStore = dataStoreService:GetDataStore("PlayerStageDataStore")

stageStore:SetAsync(player.UserId, 0)
#

yeah?

marble oasis
#

yea but if its a temporary thing and you want to do it for a specific user, you replace the player.UserId with the user id of the player u want to reset the progerss for

#

for example if i want to reset my own progress itll be smth like

local dataStoreService = game:GetService("DataStoreService")
local stageStore = dataStoreService:GetDataStore("PlayerStageDataStore")

stageStore:SetAsync("1759735120", 0)```
#

@void sedge give more context on why u want their data to be gone

rancid joltBOT
#

studio** You are now Level 8! **studio

void sedge
#

i can go back to the beggining

#

and redo it

#

that's all

#

that's the context

marble oasis
#

dawg

#

like do u want it to be reset if they [press a button or everytime they leave and rejoin??

void sedge
#

?

#

no just 1 time

marble oasis
#

ok 1 time but how

void sedge
#

like

#

they're at lvl 10

marble oasis
#

like they press a button to reset?

void sedge
#

i reset their progress

#

no

marble oasis
#

oh

#

like a rebirth?

void sedge
#

i reset it for them

#

yes kind of like a rebirth

marble oasis
#

oh like an admin panel

void sedge
#

no

#

dude

marble oasis
#

they cant reset it but u can

void sedge
#

Yeah

#

ok picture this

#

they're at lvl 10

#

I want to reset their progress

#

They get sent back to 0

#

They get to lvl 3 and leave

#

They join back the next day and theyre still at 3

#

not back to 10 or 0

marble oasis
#

so as soon as they hit level ten u want it to reset their progress

void sedge
#

No

#

When did I say that

marble oasis
#

bro then what u want is just a command in f9 console

#

yea

#

its not code or anything

void sedge
#

Yes

#

Neck just told me that

marble oasis
#

ok

#

i js gave u the code for it

void sedge
#

Yeah

#

I know

marble oasis
#

so ur good??

void sedge
#

Yes

marble oasis
#

😭

#

lmk if it works

void sedge
#

Idk you asked for context

#

Okay

#

Ill let you know in a min

marble oasis
#

ping me cus i wont be online

void sedge
#

Alright

#

Thanks

#

Bye

marble oasis
marble oasis
#

its the post above this

#

@ me in ur post

#

ok

void sedge
#

local dataStoreService = game:GetService("DataStoreService")
local stageStore = dataStoreService:GetDataStore("PlayerStageDataStore")

stageStore:SetAsync("565841008", 0)

@marble oasis Do I need the "" in the UserId??

marble oasis
#

yea u do

void sedge
#

I put it in here? @marble oasis

marble oasis
#

yea

#

in there

#

btw the user might have to rejoin, if u dont want them to do that then u have to make a longer script

void sedge
#

Its not working @marble oasis

marble oasis
#

tell the persont o rejoin

void sedge
#

I rejoined

#

I used it on myself

#

can't I do that

#

?

marble oasis
#

it didnt work?

void sedge
#

No

marble oasis
#

try lua game.Players.LocalPlayer.leaderstats.Stage.Value = 0

#

its not gonna teleport u but just reset

void sedge
#

okay is there a place i put my id in

#

or

#

no

#

cause

marble oasis
#

no

#

this one is js for u

#

if u want to do for someone else

#

just do lua game.Players.(users).leaderstats.Stage.Value = 0

void sedge
#

ok dude fuck this

marble oasis
#

replace the (users) with the players username

#

lmfao

void sedge
#

how do i

#

how do i

#

hm

#

like

marble oasis
#

wait brb ill get on my phone

void sedge
#

be able to go between the levels

#

like you know how obbies have like arrows

#

left and right

#

so if ur on lvl 10 u can go back to 9 and then back to 10

#

like go between levels

#

thats what i mean

marble oasis
#

Make button and add script

#

To it

void sedge
#

time to learn scripting

#

😔

marble oasis
#

Nd then js make player teleport back

#

I would make the script rn butim outaide

#

I gtg now ill cya

void sedge
#

Okay

#

can I add yoyu\

#

Add*