Currency System Broken for some reason

My currency system used to work, but now it doesn’t. If you could help I would appreciate it. I even implemented new currency systems but it still doesn’t work.

Local Script:

local player = game:GetService("Players").LocalPlayer

player:WaitForChild("Coins").Changed:Connect(function(val)
	script.Parent.Text = "$" .. val
end)

script.Parent.Text = "$" .. player:WaitForChild("Coins").Value

Server Script:

local DSS = game:GetService("DataStoreService")
local CoinsDS = DSS:GetDataStore("CoinsDS")

game.Players.PlayerAdded:Connect(function(plr)
	
	local Coins = Instance.new("IntValue", plr)
	Coins.Name = "Coins"
	Coins.Value = CoinsDS:GetAsync(plr.UserId) or 1000

	Coins.Changed:Connect(function()

		CoinsDS:SetAsync(plr.UserId, Coins.Value)
		
		
	end)

end)


game.Players.PlayerRemoving:Connect(function(plr)

	CoinsDS:SetAsync(plr.UserId, plr.Coins.Value)


end)

local Players = game:GetService("Players")
game:BindToClose(function() 
	for _, player in ipairs(Players:GetPlayers()) do 
			CoinsDS:UpdateAsync(player.UserId, function() 
		end)
	end
end)
1 Like

Is the “Coins” value supposed to be in the player? I usually would expect currency to be stored in a player’s leaderstats

2 Likes

There was a folder for it, but it didn’t work then, so yes, the coins value is in the player

1 Like

Also, I think you should use “GetPropertyChangedSignal” like so:

Player:WaitForChild(“Coins”):GetPropertyChangedSignal(“Value”):Connect(function()

end)
2 Likes

Try:

local player = game:GetService("Players").LocalPlayer
local Coins = player:WaitForChild("Coins")


Coins:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = "$"..tostring(Coins.Value)
end)

script.Parent.Text = "$"..tostring(Coins.Value)
3 Likes

We just had the same thought… wow that’s cool I guess.

4 Likes

I’ll try both of your scripts, I’ll let you guys know which one works. Thanks!

1 Like

@R_obotz definitely has the better script, I just included the GetPropertySignalChanged function.

2 Likes

We pretty much have the same idea

3 Likes

It works, but here’s the question I need to know. What’s the best way to subtract the money from the player via script? (So I can make all of the scripts that subtract at the currency system actually subtract it)

1 Like
local Condition = -- Your condition
local TAKE_VALUE = 50

if Condition then
Player:WaitForChild(“Coins”).Value -= TAKE_VALUE
end

By the way, mark @R_obotz ‘s answer as the solution

1 Like

alright thank you guys for helping me.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.