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

Data Store doesn't work in game but works in Roblox Studio.....?

Asked by 5 years ago

Trying to store PlayerGui.Menu.Stats.Z.Money.Text

localScript position = game.Players.LocalPlayer.PlayerGui.Menu.Stats.Z.Money.LocalScript

    local money = script.Parent:WaitForChild("Money")
    local Gui = script.Parent

    money.Changed:connect(function()
        Gui.Text = money.Value
    end)

ServerScriptService

    local dataStore = game:GetService("DataStoreService"):GetDataStore("Money")

    function SaveData(dataname, playerid, value)
        dataStore:SetAsync(playerid, value)
    print(playerid)
    print(value)
    end

    game.Players.PlayerAdded:connect(function(player)

        local money = player.PlayerGui:WaitForChild("Menu").Stats.Z.Money["Money"]
         money.Value = dataStore:GetAsync(player.userId)

            money.Changed:connect(function()
             SaveData("Money", player.userId, money.Value)
    wait(1)
    SaveData("Money", player.userId, money.Value)
        end)
end)
0
Filter enabled? The_Pr0fessor 595 — 5y
0
yes Hypoxic1 8 — 5y
1
You cannot access the contents of the playergui that are created by a local script, I recommend moving the values in the player User#20388 0 — 5y

1 answer

Log in to vote
0
Answered by
Async_io 908 Moderation Voter
5 years ago

I know RedcommanderV2 answered your question, but I'm here to elaborate.

As I always say when I see messy code, a clean code is key to getting help faster. Your indenting is a little bit messy, but it's not a big deal. When you make a larger script, it could be problematic though.

I would suggest reviewing this article.

Now onto your actual issue

Server's can necessarily see what's inside the player. They acknowledge the existence of the PlayerGui, StarterPack, and Backpack, but they don't actually see what's contained in them.

As a visual example, this is what the client sees. Notice the arrows that show how there are children. This is what the server sees. Notice there are no arrows indicating the existence of children.

As a fix to your solution, I would consider saving the values either in ReplicatedStorage or ServerStorage.

Note that ReplicatedStorage is replicated both to the client and server, however, ServerStorage is only shown to the server.

0
All good i already Fix it thanks tho ;) Hypoxic1 8 — 5y
Ad

Answer this question