#Badge Awarding for something not in leaderstats
121 messages · Page 1 of 1 (latest)
So technically
There is no leaderstat, correct?
Just the textlabel and it changes the text
Nope. For other scripts, like adding cash via robux dev products, where I normally refer to other stuff as player.leaderstats.Wins.value, I refer to it as player.Cash.value.
It works the same way just not showing on the leaderboard.
I personally used a Datastore to store their level values and then if it's changed it changes the label
There might be a workaround to work for your system but Ima have to boot up studio myself
Is it in serverscriptservice?
yep. and the cash amount is stored in a Datastore.
** You are now Level 1! **
the textlabel just displays Cash.Value
** You are now Level 2! **
actually
why not change leaderstats to the name of your datastore cash value
So it wont look for leaderstats it'll look for the cash value
That's the problem though how do I reference something that the player has. When you reference something on leaderstats, you reference the player's leaderstats. But for my currency it's something the player directly has.
what's the name of the datastore cash value
so not the textlabel but the cash value
Oh wait. That's weird, I just realized the name of the datastore cash value is referenced like this...
Players.PlayerAdded:Connect(function(player)
`player.CharacterAdded:Connect(function(character)
local hasDied = Instance.new("BoolValue", character)
hasDied.Name = "HasDied"
hasDied.Value = false
character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if character.Humanoid.Health <= 0 and not character.HasDied.Value then
player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1
end
end)
end)
player:WaitForChild("leaderstats")
local cash = Instance.new("IntValue", player)
cash.Name = "Cash"
local wins = Instance.new("IntValue", player.leaderstats)
wins.Name = "Wins"
--local melees = Instance.new("IntValue", player.leaderstats)
--melees.Name = "Melees"
player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:Connect(function(Died)
local creator = Character.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value:FindFirstChild("leaderstats")
if creator ~= nil and creator.Value ~= nil then
leaderstats.Cash.Value = leaderstats.Cash.Value + 5
--leaderstats.Melees.Value = leaderstats.Melees.Value + 1
end
end)
end)`
So in turn my code should just work without any changes....
So the cash value is actually inside the leaderstat?
yeah but its not displayed on leaderstats
Is it inside of it?
You mean like at the top where it shows the player and like Team, Wins, etc.
yes
and inside the player should be leaderstats correct?
well yeah
so
shouldnt the cash be inside the leaderstat
so game.players.player.leaderstats.cash.value
it doesnt have to? i mean it works fine without it being inside it
I can make developer products incease it and events? It's just awarding badges causing the problems...
So I found a script online to award a badge when they have reached a certain amount of Cash or exceeded. But it does not work. I think it could be a problem with the 5th line because Cash in my cash is not in leaderstats, it's just shown as a text label on screen but if I remove that line of script I get an error about indexing nil.
local BadgeID = 2124831642 --My Badge ID local Cash = "Cash" --My Money local HowMuch = 10 --How Much They Will Need To Have game.Players.PlayerAdded:connect(function(player) repeat wait() until p:findFirstChild("leaderstats") ~= nil player.Cash.Changed:connect(function() if player.Cash.Value <= HowMuch - 1 then return end game:GetService("BadgeService"):AwardBadge(player.userId, BadgeID) end) end)
In line 10
player.Cash.Changed
shouldnt it be player.leaderstats.Cash.Changed
yes
uh
No that's not how it's referenced in other scripts like let me show you an example.
Oh wait. That's weird, I just realized the name of the datastore cash value is referenced like this...
Players.PlayerAdded:Connect(function(player)
`player.CharacterAdded:Connect(function(character)
local hasDied = Instance.new("BoolValue", character)
hasDied.Name = "HasDied"
hasDied.Value = false
character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if character.Humanoid.Health <= 0 and not character.HasDied.Value then
player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1
end
end)
end)
player:WaitForChild("leaderstats")
local cash = Instance.new("IntValue", player)
cash.Name = "Cash"
local wins = Instance.new("IntValue", player.leaderstats)
wins.Name = "Wins"
--local melees = Instance.new("IntValue", player.leaderstats)
--melees.Name = "Melees"
player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:Connect(function(Died)
local creator = Character.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value:FindFirstChild("leaderstats")
if creator ~= nil and creator.Value ~= nil then
leaderstats.Cash.Value = leaderstats.Cash.Value + 5
--leaderstats.Melees.Value = leaderstats.Melees.Value + 1
end
end)
end)`
in this code it references it through the leaderstat?
ik it is referenced that way
leaderstats.Cash.Value
but if u take a look at this script i made
'local Players = game:GetService("Players")
local mps = game:GetService("MarketplaceService")
mps.ProcessReceipt = function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if player then
if receiptInfo.ProductId == 1208410513 then
player.Cash.Value += 100
elseif receiptInfo.ProductId == 1342774613 then
player.Cash.Value += 1000
elseif receiptInfo.ProductId == 1342770170 then
player.Cash.Value += 300
elseif receiptInfo.ProductId == 1342771507 then
player.Cash.Value += 500
elseif receiptInfo.ProductId == 1343023770 then
player.leaderstats.Wins.Value += 30
elseif receiptInfo.ProductId == 1343022593 then
player.leaderstats.Wins.Value += 10
end
else
return Enum.ProductPurchaseDecision.NotProcessedYet
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end'
It's referenced as player.Cash.value and it works fine
I tested it
I bought the dev product
and it awarded me the cash
did you check the value to be sure it changed?
yeah it went from 790
** You are now Level 2! **
to 890
yep
sooo
its that FindFirstChild
line
thats causing problems
idk what to replace leaderstats
as
game.Players.PlayerAdded:connect(function(player)
repeat wait() until p:findFirstChild("Cash") ~= nil
Should it be Cash or should it be Player?
you should change p to player
so it finds the first child of the player which is Cash
and make sure FindFirstChild is capital
capitalized
hmmmm let my try that
Alrighty, let me know how it goes!
ok
if you put function(Player) then wherever you put Player needs to be capital
Lmk if it works!
** You are now Level 3! **
It didn't work out @terse lichen
It didnt?
yk what
So I found a script online to award a badge when they have reached a certain amount of Cash or exceeded. But it does not work. I think it could be a problem with the 5th line because Cash in my cash is not in leaderstats, it's just shown as a text label on screen but if I remove that line of script I get an error about indexing nil.
local BadgeID = 2124831642 --My Badge ID local Cash = "Cash" --My Money local HowMuch = 10 --How Much They Will Need To Have game.Players.PlayerAdded:connect(function(player) repeat wait() until p:findFirstChild("leaderstats") ~= nil player.Cash.Changed:connect(function() if player.Cash.Value <= HowMuch - 1 then return end game:GetService("BadgeService"):AwardBadge(player.userId, BadgeID) end) end)
nope didnt work out
I did that if you read it
one sec
That give a error
I know but one second
Okay.
is it a local script or normal script?
one second
try a local script instead of a normal script and put this below the variables
game.Players.LocalPlayer.Cash.Changed:connect(function(player)
if player.Cash.Value <= HowMuch - 1 then return end
game:GetService("BadgeService"):AwardBadge(player.userId, BadgeID)
end)
end)`
so altogether itll be
`local BadgeID = 2124831642 --My Badge ID
local Cash = "Cash" --My Money
local HowMuch = 10 --How Much
game.Players.LocalPlayer.Cash.Changed:connect(function()
if player.Cash.Value <= HowMuch - 1 then return end
game:GetService("BadgeService"):AwardBadge(player.userId, BadgeID)
end)
end)`
so where do i put the local script again @terse lichen
StarterPlayerScripts
okay im testing it
Alright