[EDIT] It is now adding the cash by 100. Say I have 17 dollars, and I click the ATM. I now have 100. If I were to spend all the money, and then click the ATM, I would have 200.

I have an ATM that, when clicked, gives the player 100 cash. However, it does not take the cash you already have and add 100 to it. It simply resets the player's cash, and then gives them 100 cash.

Why is this happening? I want 100 cash to be added to the player's funds that they have already.

Code:

clickDetector = script.Parent.ClickDetector
isHackable = script.isHackable
text = script.Parent.TextPart.SurfaceGui.TextLabel
cashSound = script.CashSound
startSound = script.Startup

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)

Leaderstats:

game.Players.ChildAdded:connect(function(player)
local stats = Instance.new("Model",player)
stats.Name="leaderstats"
local Cash = Instance.new("IntValue",stats)
Cash.Name="Cash"
Cash.Value=0 -- Change Your Starting Money
end)

5 comments

0

You are using a Server Script?

0

The script is inside of an ATM model. It's not a local script.

0

Can you show us your leaderstats script?

0

Leaderstats in description

0

Why do you use ChildAdded instead of PlayerAdded, also :connect is deprecated, try to remember to have an uppercase c