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.
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!
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)
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
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)
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)
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)
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.
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
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)