Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I want to make a award badge script what do I change?

Asked by 1 year ago

So, I found a script online to award a badge when they have reached a certain amount of Cash or exceeded. I made some adjustments, but it still 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. I refer to it as player.Cash.Value in other scripts like my developer product to award more cash or my shop to buy weapons because it's a part of the player but not a part of the player's leaderstats. I have made other changes as found in the second attempt; I added but still doesn't work. I made a local script for the third attempt and, put it in StarterPlayerScripts.

Script 1

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 player: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)

Script 2

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 player:findFirstChild("Cash") ~= nil 
    player.Cash.Changed:connect(function() 
        if player.Cash.Value <= HowMuch - 1 then return end 
        game:GetService("BadgeService"):AwardBadge(player.userId, BadgeID) 
    end)
end)

LocalScript 3

local BadgeID = 2124831642 --My Badge ID
local Cash = "Cash"  --My Money
local HowMuch = 10 --How Much 


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)

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

all of this isn't really necessary

you just need one script in ServerScriptService here is the script, feel free to copy and paste:

local BadgeID = 2124831642 --My Badge ID
local HowMuch = 10 --How Much 
local BadgeService = game:GetService("BadgeService")


game.Players.PlayerAdded:connect(function(player)
while wait(0.01) do
    if player.Cash.Value >= HowMuch then 
    BadgeService:AwardBadge(player.userId, BadgeID)
end
end
    end)
Ad

Answer this question