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

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

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)

3 comments

0

Filter enabled?

0

yes

1

You cannot access the contents of the playergui that are created by a local script, I recommend moving the values in the player

1 answer

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.

1 comment

0

All good i already Fix it thanks tho ;)

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