#Stage Saving Script Error
182 messages · Page 1 of 1 (latest)
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
lua is case sensitive
yeah
so instead of UserID
typo
its UserId
You need UserId not UserID
lowkey got confused what was wrong and then realized the capital D
is there a button to send them back to stage 0?
no
or do uw ant to do it for everyone
like reset progress for one player or for everyone
1 player
are they able to do it at their own will?
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.
oh
open game settings, go to security and turn on "Enable Studio Access to API Services"
Okay
game settings is in ur home tab btw
do u want the player to reset their progress by themselves or u want to reset for them
ok sick u can just lua stageStore:SetAsync(player.UserId, 0)
where it says userId u put the player's user id?
yea replace the player.userid with the users id
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
when u join the game
like will u reset the progress for them one time thing?
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
yea
ok sick u join the game, press F9, click on server and then paste this code in
Yeah so that it doesn't always put them at 0 no matter what stage they're at
Shouldn't it say (player.UserId, 0) ?
or just (UserId, 0)
u have to mention the players id if u want it to work
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?
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
so that
** You are now Level 8! **
dawg
like do u want it to be reset if they [press a button or everytime they leave and rejoin??
ok 1 time but how
like they press a button to reset?
oh like an admin panel
they cant reset it but u can
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
so as soon as they hit level ten u want it to reset their progress
bro then what u want is just a command in f9 console
yea
its not code or anything
so ur good??
Yes
ping me cus i wont be online
can u help me
yeae sure
its the post above this
@ me in ur post
ok
local dataStoreService = game:GetService("DataStoreService")
local stageStore = dataStoreService:GetDataStore("PlayerStageDataStore")
stageStore:SetAsync("565841008", 0)
@marble oasis Do I need the "" in the UserId??
yea u do
I put it in here? @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
Its not working @marble oasis
tell the persont o rejoin
it didnt work?
No
try lua game.Players.LocalPlayer.leaderstats.Stage.Value = 0
its not gonna teleport u but just reset
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
ok dude fuck this
wait brb ill get on my phone
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