Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I Made this save script and im getting this error help?

Asked by
abrobot 44
5 years ago
game.Players.PlayerAdded:connect(function(player)
    local PlayerStorege = player:WaitForChild("PlayerStorege")
    local RemoteSAVE = PlayerStorege:WaitForChild("RemoteSAVE")
    local RemoteLOAD = PlayerStorege:WaitForChild("RemoteLOAD")
    local Cash = player.PlayerStats:WaitForChild("Cash")

    wait(5)
    Cash.Value = PlayerCashDataStore:GetAsync(player.UserId) or 0
    if PlayerCashDataStore:GetAsync(player.UserId) == 0 then
    Cash.Value = 100
    PlayerCashDataStore:SetAsync(player.UserId, Cash.Value)
            else
    end

ERROR Unable to cast value to function

0
If you posted the full code that would help alot, and the error explains itself User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by
abrobot 44
5 years ago
local DataStore = game:GetService("DataStoreService")
local PlayerCashDataStore = DataStore:GetDataStore("PlayerCashDataStoreeee")



game.Players.PlayerAdded:connect(function(player)
    local PlayerStorege = player:WaitForChild("PlayerStorege")
    local RemoteSAVE = PlayerStorege:WaitForChild("RemoteSAVE")
    local RemoteLOAD = PlayerStorege:WaitForChild("RemoteLOAD")
    local Cash = player.PlayerStats:WaitForChild("Cash")

    wait(5)
    Cash.Value = PlayerCashDataStore:GetAsync(player.UserId) or 0
    if PlayerCashDataStore:GetAsync(player.UserId) == 0 then
    Cash.Value = 100
    PlayerCashDataStore:SetAsync(player.UserId, Cash.Value)
            else
    end

    RemoteSAVE.OnServerEvent:connect(function(player)

    print("Saving Data for player " .. player.Name .. " of "..Cash.Value)   
    PlayerCashDataStore:UpdateAsync(player.UserId, Cash.Value)
    end)


    RemoteLOAD.OnServerEvent:connect(function(player)   
    Cash.Value = PlayerCashDataStore:GetAsync(player.UserId)
    end)    
    RemoteLOAD.OnServerEvent:connect(function(player)
    wait(1)
    local PlayerGui = player:WaitForChild("PlayerGui")
    local CashDisplay = PlayerGui:WaitForChild("CashDisplay")
    local CashFrame = CashDisplay:WaitForChild("CashFrame")
    local CashGui = CashFrame:WaitForChild("Cash")
    CashGui.Text = "$".. Cash.Value 
    end)
end)



Ad

Answer this question