#save last place the player visited and put the player back into it.
342 messages · Page 1 of 1 (latest)
so what can i do
-- 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
ill try it
coz its mine
wait
alr
Studio
correction: it doesnt let you teleport between places in studio
just tried it again to make sure
Let me test
ok
so like
when you join a game
and move to somewhere
and when you rejoin you span at the same place
** You are now Level 1! **
thats what u want?
Oh alr
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
yea
a game and there games
it needs it to work properly
ok ok
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
Alr
i want him to spawn back at level 4
serverscript
and idk the 3rd name
i forgor
ah wait
sss
serverscriptservice
i see
ai almost broke my game with the last scrpt it sent me yesterday
wait
omg
brilliant
?
can twe use leaderstats
yh
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
you should prolly use datastore for saving the last place
idk how tho
its not that difficult
im not familiar to dss
there's tutorials on yt or just on the roblox website
it's a good thing to learn, core part of roblox games
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
dss?
data store service
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...
this one's a bit more compact
until i learn how to use data store service for it
30 mins
wdym leaderstats
the leaderboard as a unit called level
leaderstat scores dont get preserved across different sessions without datastore
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
sure but the leaderstat score is just gonna get reset once you rejoin
unless you use datastore
i dont but i can do it
** You are now Level 6! **
@foggy nimbus i made the leaderboard and it works, problem is that idk how to access leaderboard values from other scripts
can u send ss?
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
lemme make an exaple script
kk
should be smth like Teleportservice:TeleportAsync(placeID, plr)
i think
for level == 1 the id is 16310469548
do you know the require function?
no
use the script where you want to see its value
wdym
yea
yes
load it
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
he sleeping
** You are now Level 4! **
hes online
can u come on the game and help me directly
what is ur user
wait
k
k
ill make a new game and give u access
TheBaconCapIain
dont see it
k
and go to my games -> shared with me
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
Startingvalue might be the problem
done
tested and it works
put back to 0
why
y
No
then how will it work for other players
join the game
u joined in studio?
yes
i dont see u
** You are now Level 7! **
what now
so
** You are now Level 5! **
so
if value == 1
then
tp player to gameID
this is why
wait
lemme try smth
bruh
idek how bruh
?
oh
@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
yessir
good job
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