Shop with DataStore

Hi so I’ve maked an shop that is saving. I don’t know why but my script to buy doesn’t work, any help?

Shop Script That change the money collected per coin
game.Workspace["MAP 1"].Shop.Circle.Attachment.ProximityPrompt.Triggered:Connect(function()
	local TweenService = game:GetService("TweenService")
	script.Parent.Parent.Enabled = true
	TweenService:Create(game.Lighting.Blur, TweenInfo.new(0.3), {Size = 24})
	workspace["MAP 1"].Shop.Circle.Attachment.ProximityPrompt.Enabled = false
	
end)
	
script.Parent.Frame["1Multiplicator"].Upgrade.Button.MouseButton1Click:Connect(function()
	local leaderstats = game.Players.LocalPlayer.leaderstats

	if leaderstats.Multiplier.Value == 0 then
		if leaderstats["Coins 💰"].Value >= 50 then

			leaderstats.Multiplier.Value = 1
			game.ReplicatedStorage.MoneyPerCoin.Value = 2
			leaderstats["Coins 💰"].Value -= 50

			script.Parent.Frame["1Multiplicator"].Bar.UIGradient.Offset = Vector2.new(0.1, 0)
			script.Parent.Frame["1Multiplicator"].Label = "Coins Multiplicator (x2)"
		end
	end

	if leaderstats.Multiplier.Value == 1 then
		if leaderstats["Coins 💰"].Value >= 250 then

			leaderstats.Multiplier.Value = 2
			game.ReplicatedStorage.MoneyPerCoin.Value = 3
			leaderstats["Coins 💰"].Value -= 250

			script.Parent.Frame["1Multiplicator"].Bar.UIGradient.Offset = Vector2.new(0.2, 0)
			script.Parent.Frame["1Multiplicator"].Label = "Coins Multiplicator (x3)"
		end
	end

	if leaderstats.Multiplier.Value == 2 then
		if leaderstats["Coins 💰"].Value >= 500 then

			leaderstats.Multiplier.Value = 3
			game.ReplicatedStorage.MoneyPerCoin.Value = 4
			leaderstats["Coins 💰"].Value -= 500

			script.Parent.Frame["1Multiplicator"].Bar.UIGradient.Offset = Vector2.new(0.2, 0)
			script.Parent.Frame["1Multiplicator"].Label = "Coins Multiplicator (x4)"
		end
	end
end)
Datastore Creation Script
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("MyDataStore")

-- # COINS # --

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local currency = Instance.new("IntValue")
	currency.Name = "Coins 💰"
	currency.Parent = leaderstats
	
	local data
	local succes, errormsg = pcall(function()
		data = MyDataStore:GetAsync(player.UserId .. "-Coins")
	end)
	
	if succes then
		currency.Value = data
	end
	------------------
	
	local currency2 = Instance.new("IntValue")
	currency2.Name = "Multiplier"
	currency2.Parent = leaderstats

	local data2
	local succes2, errormsg2 = pcall(function()
		data2 = MyDataStore:GetAsync(player.UserId .. "-Multiplier")
	end)

	if succes2 then
		currency2.Value = data2
	end
	
	------------------
	
	local currency3 = Instance.new("IntValue")
	currency3.Name = "Zone"
	currency3.Parent = leaderstats

	local data3
	local succes3, errormsg3 = pcall(function()
		data3 = MyDataStore:GetAsync(player.UserId .. "-Zone")
	end)

	if succes3 then
		currency3.Value = data3
	end

end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local succes, errormsg = pcall(function()
		MyDataStore:SetAsync(player.UserId .. "-Coins", player.leaderstats["Coins 💰"].Value)
	end)

	if succes then
		print("Succesfully saved data.")
	end
	------------------
	local succes2, errormsg2 = pcall(function()
		MyDataStore:SetAsync(player.UserId .. "-Multiplier", player.leaderstats["Multiplier"].Value)
	end)

	if succes2 then
		print("Succesfully saved data.")
	end
	------------------
	local succes3, errormsg3 = pcall(function()
		MyDataStore:SetAsync(player.UserId .. "-Zone", player.leaderstats["Zone"].Value)
	end)

	if succes3 then
		print("Succesfully saved data.")
	end
	
end)

-- # Multiplier # --


image

1 Like

Could you use remote events to change values on server?

2 Likes

I can but i’am not the best at remote event, I use them just for proximity prompt.

1 Like

so add a Multiplicator remote event and a purchase remote event. Then a server script in server script service and change the values there.

1 Like

can I see the script data by any chance so i can see what is wrong? Thanks, MineGameIdle.

1 Like

How could I give you the script data, thanks for helping me!

The scripts are above in the drop down.

Thank, sorry i didnt see that.
-MineGameIdle

2 Likes

why is this not --continue i think this may be a error?

Where do I put --continue??? Could you help me, I don’t use datastore that much

no in ur script u have continue which is not a script part.

I don’t see any --continue, – is like # in python it’s when the code wont work like you can enter text …

If anybody could help it’s would be really cool

This is where you have continue


if saving.Value == true then
				for _, item in pairs(fc:GetChildren()) do			
					if data then
						item.Value = data[item.Name.." "..folder.Name]
						continue
					else
						warn("There is no data!")
						continue
					end
				end				
			end

can i see your explorer with where the codes are and gui’s?

I changed all my scripts, so now I have 2 problems:

  • The Multiplier and Teleport don’t save but the coins leaderstats save
  • When It’s removing money, I just need to collect another coin and that regiving my money

Are you sure you are changing the value in the server?

I think they are not saving because it’s too big of a load. I would recommend you add BindToClose because the last player to leave a server won’t get its data saved because the server will close too quickly. Also storing those values into a table would be a much better choice and also faster.

I don’t know, I create a localscript and not an script

could you help me do it? I don’t use datastore and leaderstats that much