#Can someone see my datastore and say to me if will be any issue later ?

1 messages · Page 1 of 1 (latest)

hallow meadow
#

i am kinda new at scripting but i want to know if datastore i did will have any issue later or its good

#
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)
past crow
#

disconnect "while task.wait(60) do" when player exits game

hallow meadow
#

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

red oyster
past crow
#

ye the command always runs

hallow meadow
#

right

#

ok what should i do ?

#

i say playerleave then for example stop = false and up we start stop = true ?

past crow
#

while game.Players:FindFirstChild(plr.Name) do
task.wait(60)
pcall function ( ... )

(...)
end

#

it's the easiest way

hallow meadow
#
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 ?
past crow
#

No

#

there will be on average 4+ players and not just one player

hallow meadow
#

ohh right i am dumb sorry

past crow
#

local stop = {}
you can use tables but is a little more "hard"

hallow meadow
#
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 ?
past crow
#

the string will not change

hallow meadow
#

oh i mean id i forgot

#

plr.userid

past crow
#

Plr.UserID is a string/number too

#

so it will never change even if the Player leaves

hallow meadow
#

can u edit me code

past crow
hallow meadow
#

i can just write plr not game.player right ?

red oyster
#

while player.Parent and taskwait

past crow
past crow
hallow meadow
past crow
hallow meadow
#

my brain X_X

past crow
hallow meadow
#

plr.parent is players service right ?

past crow
#

yes

#

but you can't get the Parent of something NIL

hallow meadow
#

ok so i like this say while players service do
and its always true

red oyster
#

don't quit your day job hehe

hallow meadow
hallow meadow
#
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 ?

past crow
#

yes at least it works

hallow meadow
#

ok so data store will not have any problems later right ?

past crow
#

maybe

hallow meadow
#

?

past crow
#

because there is profile service too but you better use the DataStore

hallow meadow
#

wtf u mean profile profile service

past crow
hallow meadow
#

nah i will just be happy what i learn lol

past crow
#

that's what i said

hallow meadow
#

okk

red oyster
#

this thread is a disaster KEKW

past crow
red oyster
hallow meadow
red oyster
#

docs only

hallow meadow
#

bruh

red oyster
#

not even youtube tutorials because those didnt exist when i started lol

hallow meadow
#

ok but atleast script help is soo much faster

past crow
#

use forums and the API

hallow meadow
past crow
#

are the best

red oyster
#

helping others is how i help learn for myself

hallow meadow
red oyster
#

coz people ask weird things that i might never see otherwise

hallow meadow
#

ok ty guys for helping

past crow
red oyster
hallow meadow
red oyster
past crow
past crow
#

because otherwise there would be no way to save the date of whoever left

hallow meadow
red oyster
#

you don't want to be exactly on the request limit, always want to be slightly under it

past crow
#

it would be better to change after 2 minutes after there is a change in leaderstats ?

red oyster
#

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

red oyster
#

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

hallow meadow
#

for how many years u been scripting ? @red oyster

#

i am 8 days right now

past crow
#

I have some questions too

#

@hallow meadow What do you want to do by learning scripts?

hallow meadow
#

and u ?

past crow
#

I make my own games and take some commissions

hallow meadow
#

nicee

#

for robux right ?

past crow
#

yes

hallow meadow
#

woow

#

10 robux ?

past crow
#

10?

hallow meadow
#

more ?

past crow
#

10k you say?

hallow meadow
#

10 only

past crow
#

i get 1k-2k per comm

hallow meadow
#

fuck

#

hooooowowowowowoow

past crow
#

It depends on how long it takes to do it too

hallow meadow
#

what things u do ?

past crow
#

uhh I script?

hallow meadow
past crow
#

oh

#

any type of system

hallow meadow
#

can u become my teacher lol

past crow
#

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

hallow meadow
#

bro its not easy

#

or maybe bec i am at day 8 of learning

past crow
past crow