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

Storing DataStore inside a TextLabel?

Asked by
Sxerks3 65
8 years ago

So, I've made the DataStore, and it's working fine. When I wanted it to print "Working" in the Output, it works, which means I've done the DataStore correctly. How would I display it inside a TextLabel? In this case, I got it so you have to touch a part, which is the parent of the script, for it to show the DataStore value. But, the textlabel doesn't do as told.

local datastore = game:GetService("DataStoreService"):GetDataStore("currency")

game.Players.PlayerAdded:connect(function(player)
    local key = "user_"..player.userId
    datastore:UpdateAsync(key, function(oldcurrency)
        local newcurrency = oldcurrency or 0
        return newcurrency
    end)
end)

game.Players.PlayerAdded:connect(function(player)
    script.Parent.Touched:connect(function()
        local key = "user_"..player.userId
        local coin = datastore:GetAsync(key)
        game.StarterGui.ScreenGui.Frame.TextLabel.Text = coin
    end)
end)

1 answer

Log in to vote
1
Answered by 8 years ago

The problem i see is that your attempting to change something in starterGui rather than the player's gui. So on line 15 replace it with

player.PlayerGui.ScreenGui.Frame.TextLabel.Text = coin

In order for a player to see a screen gui object, it has to be placed in a playergui which explains why it didn't work properly for you

0
Many thanks! Sxerks3 65 — 8y
Ad

Answer this question