#DataStore isn't working

1 messages · Page 1 of 1 (latest)

hushed lodge
#
local ds = game:GetService("DataStoreService")
local moneyData = ds:GetDataStore("MoneyData")

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = plr
    
    local money = Instance.new("NumberValue")
    money.Name = "Money"
    money.Parent = leaderstats
    
    task.wait()
    
    local success, hasMoney = pcall(function()
        return moneyData:GetAsync(plr.UserId)
    end)
    
    if success and (hasMoney ~= 0) then
        money.Value = hasMoney
        print(money.Value, hasMoney)
    else
        moneyData:SetAsync(plr.UserId, 0)
    end
end)

Players.PlayerRemoving:Connect(function(plr)
    local leaderstats = plr:WaitForChild("leaderstats")
    local money = leaderstats:WaitForChild("Money")
    
    local success, errMsg = pcall(function()
        moneyData:SetAsync(plr.UserId, money.Value)
    end)
    
    if success then
        print("Saved",  money.Value)
    else
        print(errMsg)
    end
end)

Am I doing something wrong?

bleak laurel
#

If first time

hushed lodge
#

yeah

#

So I got this

#

if success and (hasMoney ~= 0) then
money.Value = hasMoney
print(money.Value, hasMoney)
else
moneyData:SetAsync(plr.UserId, 0)
end

#

O yeah that was old script, I actually changed it to this

#

if success and hasMoney then
money.Value = hasMoney
print(money.Value, hasMoney)
else
moneyData:SetAsync(plr.UserId, 0)
end

bleak laurel
#

Ye that's the part I was confused about

#

Any errors

#

Or prints

hushed lodge
#

No

#

There's no errors but there's the

#

print

#

It always prints 0 0

#

Even if I changed my value to 50 last time before retesting

bleak laurel
#

Mmmm

#

Gtg lesson

hushed lodge
#

what

bleak laurel
#

How

bleak laurel
#

Gonna go

bleak laurel
hushed lodge
#

client

#

on the specific player that touched the part (coin)

bleak laurel
hushed lodge
#

:/

#

Man

#

I forgot about that

bleak laurel
#

Client doesn't replicate to server

#

U gonna change on server

#

Or it will always be 0 for server

hushed lodge
#

ok

#

I think

#

I'ma use removeevents

#

Thanks :D

bleak laurel
#

That's not what do it on server means for stats

#

U should detect the .touched on server

hushed lodge
#

welp

#

It works

bleak laurel
#

Clients can lie in remotes

#

Cheaters can send remotes with anything they want

hushed lodge
#

:/

#

Ok ima try it then

hushed lodge
bleak laurel