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