This problem is a bit hard to explain, but I'll try my best. Basically, I have 3 Items.
The First is a tool that, when used, gives the player 1 "Cash".
The Second is an ATM Model that, when clicked, gives the player 100 "Cash".
The Third is a GUI Button that, when clicked, takes away 25 "Cash" from the player, and gives them an item.
The tool and the ATM work together seamlessly, no problems. However, when the player tries to buy an item, the money is subtracted from the player's "Cash" amount like it is supposed too, but the ATM and tool don't recognize this transaction. If I go back to the ATM and withdraw 100 "Cash", it will act like the transaction never took place. The same thing happens with the tool.
For example, say I have 100 "Cash". I buy a Hot Dog from the shop for 25 "Cash". I now have 75 "Cash". But when I withdraw 100 "Cash" from the ATM, my "Cash" balance is up to 200.
My Shop (buy) code:
script.Parent.MouseButton1Click:connect(function() local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Hot Dog") local price = 25 -- Change Your Price Here local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats") if game.Players.LocalPlayer.leaderstats.Cash.Value >= price then -- Change the Cash to your Currency Name game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value - price local cloned = item:Clone() cloned.Parent = player.Backpack end end)
My leaderboard Code:
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local money = Instance.new("IntValue") --We create a new IntValue money.Name = "Cash" --this is the name you want the leader-stat to be when it shows up in-game. money.Value = 0 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later) money.Parent = leaderstats -- Set the money object as a child of the leaderstats object. end)
My ATM's Code:
clickDetector = script.Parent.ClickDetector isHackable = script.isHackable text = script.Parent.TextPart.SurfaceGui.TextLabel cashSound = script.CashSound startSound = script.Startup game.Players.PlayerAdded:Connect(function(player) print("A player has entered: " .. player.Name) isHackable = true local function onMouseClick(player) if isHackable == true then cashSound:Play() player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100 text.Text = "Rebooting..." isHackable = false wait(30) startSound:Play() isHackable = true text.Text = "Hackable!" else print("Money Cooling Down") end end clickDetector.MouseClick:connect(onMouseClick) end)
My tool's Code:
local tool = script.Parent local player = script.Parent.Parent.Parent tool.Activated:Connect(function() player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1 end)
Buy Script Location : https://ibb.co/7vq6RpM
Hope I included everything, let me know if you need more info and thanks, -Mex