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

DataStore Only 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)

2 comments

0

You have FireServer in a server script?

0

No it's not

1 answer

If you want to save your currency into the datastore, I suggest that you use an IntValue or NumberValue and put in the LocalPlayer. Here's the code to create it :

Creating Currency (ServerScript) :

-- Example code only change what you want.

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

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

game.Players.PlayerAdded:connect(function(player)
	
	-- Optional you can put in outside of leaderstats too
	local stats = Instance.new("Folder")    
	stats.Name = "leaderstats"
	stats.Parent = player
	
	-- You can also change the money.Parent to "player" (No double quotes)
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = moneyData:GetAsync(tostring(player.userId)) or 350
	money.Parent = stats
	
	while true do
		wait(.5)
		money.Changed:connect(function()
			SaveData("Money", player.userId, money.Value)
		end)
	end
end)

game.Players.PlayerRemoving:connect(function(player)
	SaveData("Money", player.userId, player.leaderstats.Money.Value)
end)

With this you can only edit the values in-game.

Putting the currency into the gui (LocalScript) :

-- Example code only change what you want.

local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local mainGui = playerGui:WaitForChild("MainGui")
local stat = game.Players.LocalPlayer:WaitForChild("leaderstats")
local money = stat:WaitForChild("Money")

local moneyGui = script.Parent.Money

moneyGui.Text = "$" .. money.Value

money.Changed:connect(function()
	desiredMoney.Value = money.Value
end)

Sorry that I don't use RemoteEvents or RemoteFunction for this method.

4 comments

0

I edited the question tell me what i have done wrong please, it's not working.

0

Nvm I fix it

0

Now it only works in studio -_-

0

Have you checked the "Save Place API" to true in the "Configure Place"? Here's the image on it, you need to configure that : https://imgur.com/a/kq6pRDQ

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