Give badge on LeaderStats Value

Hello, I am trying to give a player a badge when they reach a certain amount of cash. I am using Zed’s tycoon kit. I am not a big scripter so I do not know how to do this.

I tried finding the player and the leaderstat and comparing it to a math value. So here’s my code, it is a
localscript inside serverscriptservice.

local plr = game:GetService("Players").LocalPlayer

while true do 
	if plr.leaderstats.Cash.Value > 500 then
		print ("It worked!")
--I would put badge give code here
	end

end

I have searched the whole internet, youtube, devforum, different websites. Yet not a single topic talks about how to find the value of this. I also do not surely know, if the leaderstat is called Cash.
image
On my screen it shows cash, and it says that’s what it’s called. Yet I cannot seem to give a badge when they reached that value.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

1 Like

Try

local Players = game:GetService("Players")

local function Load(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")
	if Cash.Value >= 500 then
		print ("It worked!")
		--put badge give code here
	end
end

Players.PlayerAdded:Connect(function(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")
	Load(Player)
	Cash:GetPropertyChangedSignal("Value"):Connect(function()
		Load(Player)
	end)
end)

Put this in a script in serverscriptservice

Capture

1 Like

I will as soon as I fix my game. I did nothing and now the money collector doesn’t work. :grimacing:

I got an error, I got this.

Its for line 5,
image

I don’t see how the cash is a string? Maybe I could put the cash as a number variable. Like local cash = Cash.Value
So that then I could do if Cash >= 500 then

What type of value is cash?

I tested it and got no errors

local Players = game:GetService("Players")

local function Load(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")
	local Value = tonumber(Cash.Value)
	if Value >= 500 then
		print ("It worked!")
		--put badge give code here
	end
end

Players.PlayerAdded:Connect(function(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")
	Load(Player)
	Cash:GetPropertyChangedSignal("Value"):Connect(function()
		Load(Player)
	end)
end)
2 Likes

Try doing,

if tonumber(Cash.Value) >= 500 then

I’m using zed’s tycoon kit, so I don’t really know. But I this is what I found.
image

local plrStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)

Try like @Synnwave said

local Players = game:GetService("Players")

local function Load(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")
	local Value = tonumber(Cash.Value)
	if Value >= 500 then
		print ("It worked!")
		--put badge give code here
	end
end

Players.PlayerAdded:Connect(function(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")
	Load(Player)
	Cash:GetPropertyChangedSignal("Value"):Connect(function()
		Load(Player)
	end)
end)

You posted that when I was editing my post :laughing:

I got this now.

Hmm…

I tested it with zed’s tycoon kit and it worked just fine try adding print(Value) what is prints

local Players = game:GetService("Players")

local function Load(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")
	local Value = tonumber(Cash.Value)
	print(Value)
	if Value >= 500 then
		print ("It worked!")
		--put badge give code here
	end
end

Players.PlayerAdded:Connect(function(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")
	Load(Player)
	Cash:GetPropertyChangedSignal("Value"):Connect(function()
		Load(Player)
	end)
end)
1 Like

I think it may be because of my datastore, let me disable it real quick it and try.

Ah, it was my datastore, but I still need my datastore, so maybe my datastore is outputting the Cash as a different leaderstats name?

Once you start the game, can you show me what your player in the Explorer tab contains? Try to expand as much as possible that is related to leaderstats.

Here is what its in. But I see a leaderstat called cash?

image
image

The problem is that Zed’s tycoon kit makes cash a string value inside of leaderstats so it can add commas.

game.Players.PlayerAdded:Connect(function(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")

	Cash:GetPropertyChangedSignal("Value"):Connect(function()
		if tonumber(string.gsub(Cash.Value, ",", "")) >= 500 then
			print("Over 500")
		end
	end)
end)

Edit: I used the wrong function, so retry the script when you see this

2 Likes

I’m not getting any output for it.

I edited the script a few times, so try again if you can. If there is really no output after that, try printing each time the value is changed.

game.Players.PlayerAdded:Connect(function(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")

	Cash:GetPropertyChangedSignal("Value"):Connect(function()
		print(tonumber(string.gsub(Cash.Value, ",", "")))
		if tonumber(string.gsub(Cash.Value, ",", "")) >= 500 then
			print("Over 500")
		end
	end)
end)
1 Like

Yea I got nothing… this is the code i’m using right now. Also where should I place the scripts.

local Players = game:GetService("Players")

local function Load(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")
	local Value = tonumber(Cash.Value)
	if Value >= 200 then
		print(Value)
		print("Bigger than 200")
	end
end

game.Players.PlayerAdded:Connect(function(Player)
	local Cash = Player:WaitForChild("leaderstats"):WaitForChild("Cash")

	Cash:GetPropertyChangedSignal("Value"):Connect(function()
		print(tonumber(string.gsub(Cash.Value, ",", "")))
		if tonumber(string.gsub(Cash.Value, ",", "")) >= 500 then
			print("Over 500")
		end
	end)
end)

This should be a server script in ServerScriptService. Also, you only need

this part of the code as the rest is completely unused now.

1 Like