Updating the cash of a player

Hello,

So I am trying to make it that when a player doesn’t has enough cash to buy something then he will be notified that works just fine. But when a player has enough cash for it but he buys something else first, then his cash will be getting lowered. But when he first got enough cash for it it will say ‘This will cost 300$ are you sure?’ But he actually doesn’t haves enough cash so technically it has to say this ‘You dont have enough cash to buy this’ but he is not saying that cause his cash was first higher then the amount.

Can someone help me with this?

If you need the script here it is;

local leaderstats = player.leaderstats
local hover = game.SoundService.HoverSound

if Cash.Value < 300 then -- checks if the cash is under 300
	script.Parent.Parent.Text = "You don't have enough cash to buy this!" -- sets the text to this
	script.Parent.Text = "Close"
else
	script.Parent.Parent.Text = "This will cost: $300 Are you sure?"
end

script.Parent.MouseEnter:Connect(function()
	hover:Play()
end)

script.Parent.MouseButton1Click:Connect(function(click)
	if Cash.Value < 300 then
		warn("You dont have enough cash")
		script.Parent.Parent.Visible = false
	else
		script.Parent.Parent.Text = "This will cost: $300 Are you sure?"
		script.Parent.Text = "Purchase"
		
		script.Parent.Purchase.Disabled = true -- disables the script
		print("PurchaseScript has been disabled") -- prints what happening
		
		
		Cash.Value = Cash.Value - 300 -- sets the cash to min 300
		print("leaderstats has been changed with -300")
	
		script.Parent.Parent.Visible = false
	
		script.Parent.Parent.Parent.BackGround.Philips.PriceSetter.Visible = true
		script.Parent.Parent.Parent.BackGround.Philips.Selection.Visible = false
	
	
	
		wait(5)
	
	
		local philipsclone = game.ReplicatedStorage.Tvs.Philipstv1.PartsOfPhilips:Clone()
		philipsclone.Parent = game.Workspace
		local position = game.ReplicatedStorage.Tvs.Philipstv1.PartsOfPhilips.Screen

		-- dit en de regel eronder is voor de positie waar hij word gecloned dus in de machine
		for i, v in pairs(philipsclone:GetChildren()) do
			v.Anchored = false
			v.CanCollide = true
			v.Transparency = 0
		end
	
		-- positions	
		local rotatepositionCFrame = CFrame.Angles(0,math.rad(0), 0)
		position.CFrame = position.CFrame:ToWorldSpace(rotatepositionCFrame)
		print("The CFrame has been set")
		wait(10)
		
		wait(30)
		print("30 Seconds are over!")
		script.Parent.Parent.Parent.BackGround.Philips.PriceSetter.Visible = false
		script.Parent.Parent.Parent.BackGround.Philips.Selection.Visible = true
		script.Disabled = false
		print("PurchaseScript has been enabled")
		game.StarterGui.ComputerMenu.Menu1.Philips1Info.PurchaseChecker.Purchase.Purchase.Disabled = false
	end
end)

1 Like

Any errors in your console that we can use to debug?

1 Like

No, as far as i now there are no errors.

Maybe try to use remote event? Im sorry if this is wrong.Im still learning

1 Like

You have to check the player’s cash value everytime he clicks on the “buy” button

1 Like

No, it has to check if the player has enough cash to buy before he buys it otherwise he will get the wrong text after he presses the button.

1 Like

I’m not sure if that will work. And the last time i’ve been working with remote events is a long time ago so i don’t think that i can remember how to use them.

I didnt want force u,but if u want to try here is the link how to use remote event.who knows maybe its worth to try.

1 Like

Hello Henry,

if you are stuck on using remote events there are many YouTube videos you can go and watch to learn them again.

2 Likes

I don’t really know if this would be very helpful in my script. Cause remote events are used to connect stuff from a script to another script for example;

a player clicks on a button with a script and then the other script that is connected with the first script cause of the remote event then the second script will run and do something.

Am i right or is this totally not what it is? And if it is how can i use it for a value checker

Also,

from going onto the studio, you have not said what cash is what is bringing you up an error!

Capture5

You need to declare what cash is,

1 Like

I did but that is not showing it

wait(10) -- i put this in here so i can change the value to less or higher before it starts running

game.StarterGui.ComputerMenu.Menu1.Philips1Info.PurchaseChecker.Purchase.Purchase.Disabled = true

local player = game.Players.LocalPlayer
local Cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
local leaderstats = player.leaderstats
local hover = game.SoundService.HoverSound

if Cash.Value < 300 then -- checks if the cash is under 300
	script.Parent.Parent.Text = "You don't have enough cash to buy this!" -- sets the text to this
	script.Parent.Text = "Close"
else
	script.Parent.Parent.Text = "This will cost: $300 Are you sure?"
end

script.Parent.MouseEnter:Connect(function()
	hover:Play()
end)

script.Parent.MouseButton1Click:Connect(function(click)
	if Cash.Value < 300 then
		warn("You dont have enough cash")
		script.Parent.Parent.Visible = false
	else
		script.Parent.Parent.Text = "This will cost: $300 Are you sure?"
		script.Parent.Text = "Purchase"
		
		script.Parent.Purchase.Disabled = true -- disables the script
		print("PurchaseScript has been disabled") -- prints what happening
		
		
		Cash.Value = Cash.Value - 300 -- sets the cash to min 300
		print("leaderstats has been changed with -300")
	
		script.Parent.Parent.Visible = false
	
		script.Parent.Parent.Parent.BackGround.Philips.PriceSetter.Visible = true
		script.Parent.Parent.Parent.BackGround.Philips.Selection.Visible = false
	
	
	
		wait(5)
	
	
		local philipsclone = game.ReplicatedStorage.Tvs.Philipstv1.PartsOfPhilips:Clone()
		philipsclone.Parent = game.Workspace
		local position = game.ReplicatedStorage.Tvs.Philipstv1.PartsOfPhilips.Screen

		-- dit en de regel eronder is voor de positie waar hij word gecloned dus in de machine
		for i, v in pairs(philipsclone:GetChildren()) do
			v.Anchored = false
			v.CanCollide = true
			v.Transparency = 0
		end
	
		-- positions	
		local rotatepositionCFrame = CFrame.Angles(0,math.rad(0), 0)
		position.CFrame = position.CFrame:ToWorldSpace(rotatepositionCFrame)
		print("The CFrame has been set")
		wait(10)
		
		wait(30)
		print("30 Seconds are over!")
		script.Parent.Parent.Parent.BackGround.Philips.PriceSetter.Visible = false
		script.Parent.Parent.Parent.BackGround.Philips.Selection.Visible = true
		script.Disabled = false
		print("PurchaseScript has been enabled")
		game.StarterGui.ComputerMenu.Menu1.Philips1Info.PurchaseChecker.Purchase.Purchase.Disabled = false
	end
end)

1 Like

Okay, give me a moment I will look through this script.

Can i see hoe u organize ur gui.this may be a cause to this problems

If im not mistaken, is the purcahse button is the parent of the scripts?

Under purchase checker and then purchase and then the purchase, that script is the one that i showed u

Ok ill try my best to find the problem

1 Like

Can u try to put wait or while wait before it check the player cash.im srry if this is wrong.im on mobile rn

Uhm, I already have a wait()
The wait function is at the top of my script.