#Can someone see my datastore and say to me if will be any issue later ?
1 messages · Page 1 of 1 (latest)
local datastoreservice = game:GetService("DataStoreService")
local pointsdata = datastoreservice:GetDataStore("pointsdata")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local points = leaderstats:FindFirstChild("Points")
local success , savedpoints = pcall(function()
return pointsdata:GetAsync(plr.UserId)
end)
if success and savedpoints then
points.Value = savedpoints
end
while task.wait(60) do
pcall(function()
pointsdata:SetAsync(plr.UserId , points.Value)
end)
end
end)
game.Players.PlayerRemoving:Connect(function(plr_leave)
local leaderstats = plr_leave.leaderstats
local points = leaderstats:FindFirstChild("Points")
pcall(function()
pointsdata:SetAsync(plr_leave.UserId , points.Value)
end)
end)
disconnect "while task.wait(60) do" when player exits game
i just do it when player join bec if there was any problem happens inside game , bec game has limits of datastore and if it was too much it will not save
no they mean it will continue saving even after the player has left
ye the command always runs
oh
right
ok what should i do ?
i say playerleave then for example stop = false and up we start stop = true ?
create a table with the current game players or just find the player name in the game.Players
while game.Players:FindFirstChild(plr.Name) do
task.wait(60)
pcall function ( ... )
(...)
end
it's the easiest way
local datastoreservice = game:GetService("DataStoreService")
local pointsdata = datastoreservice:GetDataStore("pointsdata")
local stop = true
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local points = leaderstats:FindFirstChild("Points")
local success , savedpoints = pcall(function()
return pointsdata:GetAsync(plr.UserId)
end)
if success and savedpoints then
points.Value = savedpoints
end
while stop do
pcall(function()
pointsdata:SetAsync(plr.UserId , points.Value)
end)
task.wait(60)
end
end)
game.Players.PlayerRemoving:Connect(function(plr_leave)
local leaderstats = plr_leave.leaderstats
local points = leaderstats:FindFirstChild("Points")
stop = false
pcall(function()
pointsdata:SetAsync(plr_leave.UserId , points.Value)
end)
end)
```this way right ?
ohh right i am dumb sorry
local stop = {}
you can use tables but is a little more "hard"
local datastoreservice = game:GetService("DataStoreService")
local pointsdata = datastoreservice:GetDataStore("pointsdata")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local points = leaderstats:FindFirstChild("Points")
local success , savedpoints = pcall(function()
return pointsdata:GetAsync(plr.UserId)
end)
if success and savedpoints then
points.Value = savedpoints
end
while plr.Name do
pcall(function()
pointsdata:SetAsync(plr.UserId , points.Value)
end)
task.wait(60)
end
end)
game.Players.PlayerRemoving:Connect(function(plr_leave)
local leaderstats = plr_leave.leaderstats
local points = leaderstats:FindFirstChild("Points")
pcall(function()
pointsdata:SetAsync(plr_leave.UserId , points.Value)
end)
end)
```now good ?
No, use the easiest way
Plr.Name is a String
the string will not change
can u edit me code
I already sent you the answer
.
i can just write plr not game.player right ?
while player.Parent and taskwait
ye
also game.Players is a service not a Player
plr.parent is service and will never be false so code will work even if player leave right ?
plr.Parent: if the player leaves the game the plr will be Nil so it is much more optimized
my brain X_X
just pretend that Plr is an instance too (Part)
plr.parent is players service right ?
ok so i like this say while players service do
and its always true
don't quit your day job 
ohhh okk
local datastoreservice = game:GetService("DataStoreService")
local pointsdata = datastoreservice:GetDataStore("pointsdata")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local points = leaderstats:FindFirstChild("Points")
local success , savedpoints = pcall(function()
return pointsdata:GetAsync(plr.UserId)
end)
if success and savedpoints then
points.Value = savedpoints
end
while plr.Parent do
pcall(function()
pointsdata:SetAsync(plr.UserId , points.Value)
end)
task.wait(60)
end
end)
game.Players.PlayerRemoving:Connect(function(plr_leave)
local leaderstats = plr_leave.leaderstats
local points = leaderstats:FindFirstChild("Points")
pcall(function()
pointsdata:SetAsync(plr_leave.UserId , points.Value)
end)
end)
so it will be like this ?
yes at least it works
ok so data store will not have any problems later right ?
maybe
?
because there is profile service too but you better use the DataStore
wtf u mean profile profile service
search in api or video
nah i will just be happy what i learn lol
that's what i said
okk
this thread is a disaster 
what you want from a scripting-help
that's tru 
so when u start scripting u never need help ?
correct, i never got help from anyone
docs only
bruh
not even youtube tutorials because those didnt exist when i started lol
ok but atleast script help is soo much faster
use forums and the API
ok that means now we can learn things 2x faster than it was
are the best
helping others is how i help learn for myself
okk
coz people ask weird things that i might never see otherwise
ok ty guys for helping
but you waste a little time with that
anyway your code sucks but it works good enough, aside from the not cancelling when the player leaves but you got that condition in there now so it should be better. saving every 60 seconds is going to hit request limit so as long as this is your only datastore its fine
so if i want to add more what should i do
plr will never be nil. when a player disconnects, they are parented to nil, which is why checking if plr.Parent works. there's an example of this in the docs where they also use plr.ancestrychanged:Wait() to detect a disconnect https://create.roblox.com/docs/reference/engine/classes/Player#CharacterAppearanceLoaded
you can upgrade the datastore or use another service
That's what I meant..
because otherwise there would be no way to save the date of whoever left
i will go continue episode i watch and if there any upgrade, i will do it for sure
(from function)
tbh the only thing i would change is how fast it autosaves, i'd make it 2 minutes instead of 1.
you don't want to be exactly on the request limit, always want to be slightly under it
it would be better to change after 2 minutes after there is a change in leaderstats ?
if you wanted to get fancy you could add session locking but tbh you're probably better off using profileservice which does that for you
profileservice is a 3rd party module made by community to handle datastores for newbies and beginners
that would be even better, so you're not saving identical data for no reason
but then you'd need to structure all that
and add a bunch of control code
a beginner can barely handle simple use of datastore let alone complex control code and timing stuff
so... tune suggestions accordingly ;p
It's not that complex if he learned how to use basic data store
I have some questions too
@hallow meadow What do you want to do by learning scripts?
doing any thing i think about it like doing my own game and helping people in futre if i was good at script
and u ?
oh
I make my own games and take some commissions
yes
10?
more ?
10k you say?
10 only
i get 1k-2k per comm
It depends on how long it takes to do it too
what things u do ?
uhh I script?
no like waht tasks u do
can u become my teacher lol
inventory, tool, gun, game system, npc, every thing in roblox
It's easy to create any Roblox game but the hard part is having time and promoting it
It depends, I don't have much free time but if you want you can become my friend
It is
yess ty