#Badge Awarding for something not in leaderstats

121 messages · Page 1 of 1 (latest)

terse lichen
#

So how do you level up?

#

It just changes the number of the textlabel and that's it?

warm fulcrum
#

Yep.

#

When you capture the flag, it increases the cash by 10.

#

Or cash.Value.

terse lichen
#

So technically

#

There is no leaderstat, correct?

#

Just the textlabel and it changes the text

warm fulcrum
#

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.

terse lichen
#

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?

warm fulcrum
#

yep. and the cash amount is stored in a Datastore.

upbeat yokeBOT
#

studio** You are now Level 1! **studio

warm fulcrum
#

the textlabel just displays Cash.Value

terse lichen
#

Alright

#

So try to dooo

#

One sec lemme think

upbeat yokeBOT
#

studio** You are now Level 2! **studio

terse lichen
#

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

warm fulcrum
#

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.

terse lichen
#

what's the name of the datastore cash value

#

so not the textlabel but the cash value

warm fulcrum
#

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

terse lichen
#

So the cash value is actually inside the leaderstat?

warm fulcrum
#

yeah but its not displayed on leaderstats

terse lichen
#

Is it inside of it?

warm fulcrum
#

You mean like at the top where it shows the player and like Team, Wins, etc.

terse lichen
#

So like

#

inside of game.Players

#

is the player

warm fulcrum
#

yes

terse lichen
#

and inside the player should be leaderstats correct?

warm fulcrum
#

well yeah

terse lichen
#

so

#

shouldnt the cash be inside the leaderstat

#

so game.players.player.leaderstats.cash.value

warm fulcrum
#

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

terse lichen
#

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

warm fulcrum
#

yes

#

uh

#

No that's not how it's referenced in other scripts like let me show you an example.

terse lichen
#

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?

warm fulcrum
#

ik it is referenced that way

terse lichen
#

leaderstats.Cash.Value

warm fulcrum
#

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'

terse lichen
#

Alright)

#

And does it work?

warm fulcrum
#

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

terse lichen
#

did you check the value to be sure it changed?

warm fulcrum
upbeat yokeBOT
#

studio** You are now Level 2! **studio

warm fulcrum
#

to 890

terse lichen
#

hmm alright

#

so back to changing leaderstats to Cash then?

warm fulcrum
#

yep

terse lichen
#

sooo

warm fulcrum
#

its that FindFirstChild

#

line

#

thats causing problems

#

idk what to replace leaderstats

#

as

terse lichen
#

game.Players.PlayerAdded:connect(function(player)
repeat wait() until p:findFirstChild("Cash") ~= nil

warm fulcrum
#

Should it be Cash or should it be Player?

terse lichen
#

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

warm fulcrum
#

hmmmm let my try that

terse lichen
#

Alrighty, let me know how it goes!

warm fulcrum
#

should Player be capital

#

or lowercase

terse lichen
#

no

#

since you put function(player) it will be lowercase

warm fulcrum
#

ok

terse lichen
#

if you put function(Player) then wherever you put Player needs to be capital

#

Lmk if it works!

upbeat yokeBOT
#

studio** You are now Level 3! **studio

warm fulcrum
#

It didn't work out @terse lichen

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)

warm fulcrum
#

nope didnt work out

terse lichen
#

Remove the line entirely

#

so just copy and paste this

warm fulcrum
#

I did that if you read it

terse lichen
#

one sec

warm fulcrum
#

That give a error

terse lichen
#

I know but one second

warm fulcrum
#

Okay.

terse lichen
#

is it a local script or normal script?

warm fulcrum
#

normal

#

in ServerScriptService

terse lichen
#

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)`

warm fulcrum
#

so where do i put the local script again @terse lichen

terse lichen
#

StarterPlayerScripts

warm fulcrum
#

okay im testing it

terse lichen
#

Alright

warm fulcrum
#

We have problems without testing

#

@terse lichen

terse lichen
#

Oh right

#

put (player) inside the function

#

and remove the second end)

warm fulcrum
#

Well I will work on this again tommorow.

#

I gotta sleep. I guess.