#save last place the player visited and put the player back into it.

342 messages · Page 1 of 1 (latest)

foggy nimbus
#

wdym by last place

#

like the last position?

#

or quite literally last place

misty sluice
#

last place

#

in a game

foggy nimbus
#

oh okay

#

i'm not sure

#

i haven't done that much with places

misty sluice
#

so what can i do

proven phoenix
#
-- Define a function to save the player's last visited place
local function saveLastPlace(player)
    -- Get the player's last visited place
    local lastPlace = player:FindFirstChild("LastPlace")
    
    -- Update the last visited place
    if lastPlace then
        lastPlace.Value = game.PlaceId
    else
        lastPlace = Instance.new("IntValue")
        lastPlace.Name = "LastPlace"
        lastPlace.Value = game.PlaceId
        lastPlace.Parent = player
    end
end

-- Define a function to teleport the player to their last visited place
local function teleportToLastPlace(player)
    -- Get the player's last visited place
    local lastPlace = player:FindFirstChild("LastPlace")
    
    -- Teleport the player to their last visited place
    if lastPlace then
        local placeId = lastPlace.Value
        game:GetService("TeleportService"):Teleport(placeId, player)
    end
end

-- Save the player's last visited place when they leave the game
game.Players.PlayerRemoving:Connect(saveLastPlace)

-- Teleport the player to their last visited place when they rejoin the game
game.Players.PlayerAdded:Connect(teleportToLastPlace)
#

to use this

#

add a script into serverscriptservice

#

i am not sure if this works tho

misty sluice
#

ill try it

proven phoenix
#

coz its mine

misty sluice
#

wait

proven phoenix
#

alr

misty sluice
#

do i test in studio

#

or do i play the game on client

proven phoenix
#

Studio

misty sluice
#

ok

#

last thing

#

do i only put on starter place

proven phoenix
#

yes

#

i think so

misty sluice
#

just tried it again to make sure

proven phoenix
#

Let me test

misty sluice
#

ok

proven phoenix
#

so like

#

when you join a game

#

and move to somewhere

#

and when you rejoin you span at the same place

leaden tokenBOT
#

studio** You are now Level 1! **studio

proven phoenix
#

thats what u want?

misty sluice
#

like

proven phoenix
#

Oh alr

misty sluice
#

lemme get an example

#

when you play blox froot and you are on 3rd sea

#

and you leave the game

#

when you rejoin it puts you back into sea 3

proven phoenix
#

mmh

#

so like

#

it teleports you to the same game

misty sluice
#

yea

proven phoenix
#

alr

#

is your game like blox fruit?

#

like

misty sluice
#

nop

#

but

proven phoenix
#

a game and there games

misty sluice
#

it needs it to work properly

proven phoenix
#

ok ok

misty sluice
#

and that script doesnt work

#

so

#

its a backrooms game

#

when lets say, im on level 4 and leave

#

i dont want the player to do all the way back to level 4

#

from level 0

proven phoenix
#

Alr

misty sluice
#

i want him to spawn back at level 4

proven phoenix
#

try with

#

localscript

misty sluice
#

where do i put it

#

in ps

#

sps

proven phoenix
#

serverscript

#

and idk the 3rd name

#

i forgor

#

ah wait

#

sss

#

serverscriptservice

misty sluice
#

ur saying

#

local script

#

in sss

#

that wont work

proven phoenix
#

alr

#

ththry with ai help

#

try*

misty sluice
#

tried

#

both yesterday and today

#

doesnt work

proven phoenix
#

i see

misty sluice
#

ai almost broke my game with the last scrpt it sent me yesterday

#

wait

#

omg

#

brilliant

proven phoenix
#

?

misty sluice
#

can twe use leaderstats

proven phoenix
#

yh

misty sluice
#

to tp a player to a certain game

#

so

#

when i go to the exit

#

it adds a number to the stats

#

and depending on the number

#

it tps the player to that place

proven phoenix
#

thats kind of genius

#

right there

misty sluice
#

one proble

#

idk how to make global leaderboard

#

for all places

foggy nimbus
#

you should prolly use datastore for saving the last place

misty sluice
#

idk how tho

foggy nimbus
#

its not that difficult

misty sluice
#

im not familiar to dss

foggy nimbus
#

there's tutorials on yt or just on the roblox website

#

it's a good thing to learn, core part of roblox games

misty sluice
#

i know how to comde

#

the only 2 things idk how

#

are datastore and tools

#

most of my game is from my own script

#

the only parts that arent mine are dss

foggy nimbus
#

dss?

misty sluice
#

data store service

foggy nimbus
#

gotcha

#

wait actually thats like 50 minutes lo

#

ignore that

misty sluice
#

lol

#

well actually

#

right now

foggy nimbus
#

Advanced Roblox Scripting Tutorial #13 - Data Store / Saving Player Data (Beginner to Pro 2019)

Hey guys, i know i've been gone for a while and i apologize for that but I am back and in today's video i am going to be teaching you guys about data stores and how they work. Basically saving player data. Anyways this a very long tutorial which is m...

▶ Play video
#

this one's a bit more compact

misty sluice
#

until i learn how to use data store service for it

foggy nimbus
#

30 mins

misty sluice
#

lets use leaderstats

#

my game wont show it anyways

#

cuz its a backrooms game

foggy nimbus
#

wdym leaderstats

misty sluice
#

leaderboard

#

so

#

u start the game on lvl 0

foggy nimbus
#

i know what leaderstats are

#

i'm just not sure how that'll help

misty sluice
#

the leaderboard as a unit called level

foggy nimbus
#

leaderstat scores dont get preserved across different sessions without datastore

misty sluice
#

so when you leave level 0 it send you to level 1

#

and it sets the level to 1

#

on leaderboard

#

so

#

lets make a script that

#

if your level == 1

#

for example

#

it tps you to the place

foggy nimbus
#

sure but the leaderstat score is just gonna get reset once you rejoin

#

unless you use datastore

misty sluice
#

i have used saving leaderstats before

#

not mine tho

foggy nimbus
#

oh okay

#

if you already have the code for that then its fine

misty sluice
#

i dont but i can do it

leaden tokenBOT
#

studio** You are now Level 6! **studio

misty sluice
#

im not very good so i expect like 15 min

#

so i can find out how it works

foggy nimbus
#

okay i gtg sleep now

#

gl with that

misty sluice
#

@foggy nimbus i made the leaderboard and it works, problem is that idk how to access leaderboard values from other scripts

misty sluice
#

ok

#

the base value was 0 so i used console to make it 1

#

then stopped the game and played again

#

and it saved

#

so can u tell me how to access values on other scripts @proven phoenix

proven phoenix
#

alr wait

#

which script do you want to acces the value?

misty sluice
#

lemme make an exaple script

proven phoenix
#

kk

misty sluice
#

or nvm i wont make one

#

if Level == 1 then
teleports player to place id

proven phoenix
#

then

#

put the place id

misty sluice
#

should be smth like Teleportservice:TeleportAsync(placeID, plr)

#

i think

#

for level == 1 the id is 16310469548

proven phoenix
#

do you know the require function?

misty sluice
#

no

proven phoenix
#

ok wait

#

so

#

create a script or a use a existed one

misty sluice
#

ok

#

done

proven phoenix
#

use the script where you want to see its value

misty sluice
#

wdym

proven phoenix
#

like

#

You told me you wanna see a script value?

misty sluice
#

yea

proven phoenix
#

so

#

the script

#

you want to see its value

misty sluice
#

yes

proven phoenix
#

load it

misty sluice
#

i am not understanding anything

#

💀

proven phoenix
#

yeah alr

#

try on ai help

misty sluice
#

To load a leaderstats value from another script in Roblox, you can use the GetPlayerFromCharacter function along with the leaderstats property. Here's an example of how you can achieve this:

In the script where you want to load the leaderstats value:

-- Assuming this script is a child of a player's character

-- Get the player associated with the character
local player = game.Players:GetPlayerFromCharacter(script.Parent)

-- Check if the player exists and has a leaderstats folder
if player and player:FindFirstChild("leaderstats") then
-- Access the value you want to load
local value = player.leaderstats.ValueName.Value
-- Do something with the value
print(value)
end

Make sure to replace ValueName with the actual name of the value you want to load from the leaderstats folder. Also, ensure that this script is a child of the player's character.

In the script where you update the leaderstats value:

-- Assuming this script is running on the server

-- Get the player you want to update the leaderstats for
local player = game.Players:FindFirstChild("PlayerName")

-- Check if the player exists and has a leaderstats folder
if player and player:FindFirstChild("leaderstats") then
-- Access the value you want to update
local value = player.leaderstats.ValueName
-- Update the value
value.Value = newValue
end

Replace "PlayerName" with the actual name of the player you want to update the leaderstats for, and replace ValueName with the name of the value you want to update.

Remember to ensure that both scripts are properly placed and have the correct references to the player and the leaderstats folder.

#

thats what it gave me

#

im so lost

#

@foggy nimbus do u know anything abt loading leaderboard values on another script

proven phoenix
#

he sleeping

leaden tokenBOT
#

studio** You are now Level 4! **studio

misty sluice
proven phoenix
#

is ur script

#

a child of a players character?

#

unless you cant see its value

misty sluice
#

can u come on the game and help me directly

proven phoenix
#

what is ur user

misty sluice
#

wait

proven phoenix
#

k

misty sluice
#

just so u dont say its a hack

#

ZeroRobloxGamingYT

#

add me

proven phoenix
#

k

misty sluice
#

ill make a new game and give u access

proven phoenix
#

added

#

i can join?

misty sluice
#

1 sec

#

ill add you

#

what was ur user again?

proven phoenix
#

TheBaconCapIain

misty sluice
#

ok join

#

i put a random name

proven phoenix
#

which game

#

k

#

untilted dbz game?

misty sluice
#

nop

#

idek game ahahah

#

smth like that

#

'idek game aahahaha'

proven phoenix
#

dont see it

misty sluice
#

lemme retry

#

try now

#

refresh

#

or just open studio

proven phoenix
#

k

misty sluice
#

and go to my games -> shared with me

proven phoenix
#

k

#

joining

misty sluice
#

so

#

i got the leaderstats

#

i want to make it so when the game starts

#

if lets say, level == 1 then
teleport player to other place

proven phoenix
#

Startingvalue might be the problem

misty sluice
#

so i gotta rename

#

right?

proven phoenix
#

no

#

try puttin startingvalue to 1

#

if see player is lvl 1

#

the*

misty sluice
#

done

proven phoenix
#

ahh wait

#

leaderboard

misty sluice
#

tested and it works

proven phoenix
#

put back to 0

misty sluice
#

why

proven phoenix
#

cause

#

its the leaderboard

#

of the game

misty sluice
#

yea and?

#

i dont get it

#

where do u wanna get at

proven phoenix
#

it isnt the script

#

to teleport to the game

misty sluice
#

what

#

nvm those

#

they are for decor

#

@proven phoenix u there?

proven phoenix
#

y

misty sluice
#

so

#

in sss there is a script

#

how do i get the values of it

proven phoenix
#

lemme see

#

can i remove

#

i am testing with a bot

misty sluice
#

do whatever u want

#

wait

#

cant u do it localPlayer

#

instead of the player name

proven phoenix
#

No

misty sluice
#

then how will it work for other players

proven phoenix
#

join the game

misty sluice
#

ok

#

joined

#

what happen now

proven phoenix
#

u joined in studio?

misty sluice
#

yes

proven phoenix
#

i dont see u

misty sluice
#

try again

#

im there

leaden tokenBOT
#

studio** You are now Level 7! **studio

proven phoenix
#

k

#

nope

misty sluice
#

what now

proven phoenix
#

so

leaden tokenBOT
#

studio** You are now Level 5! **studio

proven phoenix
#

why do u wanna see the value

#

tho

misty sluice
#

so

#

if value == 1

#

then

#

tp player to gameID

#

this is why

#

wait

#

lemme try smth

#

bruh

#

idek how bruh

proven phoenix
#

idk neither

#

imma go work on my game

misty sluice
#

?

foggy nimbus
#

It was 2 am when you pinged me

misty sluice
#

oh

misty sluice
#

@foggy nimbus @proven phoenix I DID IT

#

AND IT WAS SO SIMPLE

#

YET SO EFFECTIVE

#

AND IT WAS A COINCIDENCE

#

ping me if u wanna know why

#

cuz the reason is so dumb

proven phoenix
#

good job

misty sluice
#

so

#

i say a random vid about checkpoints

#

and it used leaderboards

#

the leaderboard saved through games and when you touched the checkpoints they set the level value to 1

#

exactly what i needed

#

just needed to make it so instead of it putting you to the location of the checkpoint

#

it teleported you in the place id

#

so i started writing the script

#

and midway i thought that it wouldnt work

#

so i took the script and pasted it into the ai

#

it gave me smth i thought would work

#

but it didnt

#

aaaand

#

time for the dumbest moment ever

#

i just added a line

#

lemme paste it

#

if player.leaderstats.Level.Value == 3 then
teleportLevel1(player)
end

#

this STUPID line

#

worked

#

idk how