Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Storing DataStore inside a TextLabel?

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

✓ Accepted answer

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

1 comment

0

Many thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.