Money Check system

Over the past few days I’ve been working on some tycoon tests.
I haven’t really mastered leaderstats though, so I’ve been asking a bunch of different Questions in different topics. Its a simple made game, items, objects, etc. can be spawned with
proximity prompts.

I recently found a money system that works with Leaderstats and Gui
What I need help with is for a proximity prompt to check that the player has enough money to simply just trigger the prompt.

Currently I do not have much but I do have something.

  • Dropper 1 - FREE

  • Windows - $50

Dropper 1 is easy since you don’t have to really add any script. The prompt doesn’t even know that there is a money system involved. However, the windows which cost $50 is what i need help with. If somebody could try and help me set up a script to check if they have enough money through leaderstats, then the parts will spawn into designated location

I feel like pros are going to hate me for this but here is the proximity prompt & leaderstat scripts

proximety prompt script :arrow_down:


local part1 = game.Workspace.wall1
local part2 = game.Workspace.wall2
local part3 = game.Workspace.wall3
local part4 = game.Workspace.wall4
local part5 = game.Workspace.wall5


local proxy = script.Parent


proxy.Triggered:Connect(function()
	
	part1.Transparency = 0.3
	part2.Transparency = 0.3
	part3.Transparency = 0.3
	part4.Transparency = 0.3
	part5.Transparency = 0.3
	
	
	part1.CanCollide = true
	part2.CanCollide = true
	part3.CanCollide = true
	part4.CanCollide = true
	part5.CanCollide = true
	
	
	proxy.Enabled = false
	
	local TweenService = game:GetService("TweenService")
	local partToFade = workspace:WaitForChild("dropper2touch") 

	
	local tweenInfo = TweenInfo.new(
		0.75, -- Duration (in seconds)
		Enum.EasingStyle.Linear, -- Easing style
		Enum.EasingDirection.Out, -- Easing direction
		0, -- Number of times to repeat 
		false, -- Should the tween be reversed?
		0 -- Delay (in seconds)
	)

	
	local properties = {
		Transparency = 1, -- Fully transparent (completely faded out)
	}

	-- Create the Tween
	local tween = TweenService:Create(partToFade, tweenInfo, properties)

	-- Play the Tween
	tween:Play()

	-- Connect a function to run when the tween completes (optional)
	tween.Completed:Connect(function()
		partToFade:Destroy() -- Optional: Remove the part from the workspace when the tween is complete
	end)
	
	
	
end)


Leaderstat script :arrow_down:


game.Players.PlayerAdded:Connect(function(player)     

	local leaderstats = Instance.new("Folder") 
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local money = Instance.new("IntValue")
	money.Name = "Money" 
	money.Value = 0 
	money.Parent = leaderstats

end)

please help

1 Like
local Money = player.leaderstats.Money
local upgradeCost = 50
if Money.Value >= upgradeCost then
	Money.Value -= upgradeCost
	--perform action(in this case, unlock the dropper)
end

For this you need a reference to the player related to the current dropper/tycoon, so make a function for that according to how your game works(use FindFirstAncestor for locating the tycoon from the dropper and store the player name or user id within the tycoon to use functions like game.Players:GetPlayerByUserId/Name to get the player).

Also, your script can be simplified:

local TweenService = game:GetService("TweenService")

local proxy = script.Parent

proxy.Triggered:Connect(function()
	for i = 1, 5 do
		local part: BasePart = workspace:FindFirstChild("wall"..i)
		part.Transparency = 0.3
		part.CanCollide = true
	end
	proxy.Enabled = false
	local fadePart = workspace:WaitForChild("dropper2touch") 
	local info = TweenInfo.new(0.75, Enum.EasingStyle.Linear)
	local tween = TweenService:Create(fadePart, info, {Transparency = 1})
	tween:Play()
	tween.Completed:Once(function() fadePart:Destroy() end)
end)
proxy.Triggered:Connect(function(player)

if player.leaderstats.Money.Value > yourprice then
	
	part1.Transparency = 0.3
	part2.Transparency = 0.3
	part3.Transparency = 0.3
	part4.Transparency = 0.3
	part5.Transparency = 0.3
	
	
	part1.CanCollide = true
	part2.CanCollide = true
	part3.CanCollide = true
	part4.CanCollide = true
	part5.CanCollide = true
	
	
	proxy.Enabled = false
	
	local TweenService = game:GetService("TweenService")
	local partToFade = workspace:WaitForChild("dropper2touch") 

	
	local tweenInfo = TweenInfo.new(
		0.75, -- Duration (in seconds)
		Enum.EasingStyle.Linear, -- Easing style
		Enum.EasingDirection.Out, -- Easing direction
		0, -- Number of times to repeat 
		false, -- Should the tween be reversed?
		0 -- Delay (in seconds)
	)

	
	local properties = {
		Transparency = 1, -- Fully transparent (completely faded out)
	}

	-- Create the Tween
	local tween = TweenService:Create(partToFade, tweenInfo, properties)

	-- Play the Tween
	tween:Play()

	-- Connect a function to run when the tween completes (optional)
	tween.Completed:Connect(function()
		partToFade:Destroy() -- Optional: Remove the part from the workspace when the tween is complete

	end)

    end

end)

If your interested in a simpler system I would highly recommended watching this tutorial series:

It is very well put together.

Instead of individually calling each wall part (local part1 = game.Workspace.wall1), put them in a folder and use

for i,v in pairs(game.Workspace.Folder:GetChildren()) do
v.transparency = .3
v.cancollide = true
end

That would be better but to solve his problem you need to get the player argument from the prompt.Triggered and check if they have enough cash.

While we are all on this topic, is there a way how to subtract the money once item bought?
Otherwise it all works great

If the players money is greater then the price then do this (and maybe check if they are the tycoons owner?)

local owner = "TestPlayer"

proxy.Triggered:Connect(function(player)
 if player.Name == owner then
    if player.leaderstats.Cash.Value >= yourprice then
        player.leaderstats.Cash.Value -= yourprice
         end
      end
   end
end)
1 Like

Make sure players cash is greater than OR equal to the price.

1 Like

Yes, good point, I missed that.

2 Likes