Im currently working on a fighting game, and when a player gets a certain amount of kills it awards a badge for them. I tried doing this but I couldn’t figure it out. Heres the script:
Local badge = game:GetService(“BadgeService”)
game.LeaderBoard.Stat = leaderstat
leaderstat.Name = (“Kills”)
local Kills = 10
game:GetService(“Value”)
Value.Name = ammountofKills
ammountofKills.Value = 10
when ammountofkills.Value.10 = true then
game.RewardBadge.Player
Badge Id = “rbxassetid//0”
when ammountofkills.Value.10 = false then
RewardBadge = false
end
end)
This is hard when you are trying to make a thing where the player gets a badge rewarded to them. I have seen it in a lot of games, but I do not know how to technically make one.
Hmmm, it should not be to hard, but you can get the value of your leader stat by doing this game.LeaderBoard.Kills.Value and make a function checking if the player should receive the badge everytime the number is changed
game.LeaderBoard.Kills.Value.Changed:Connect(function()
if game.LeaderBoard.Kills.Value>5 then
badge award code here
end
end)
Edit:znimator solved it before me, you win lol.
local BadgeService = game:GetService("BadgeService")
Kills:GetPropertyChangedSignal("Value"):Connect(function(newValue)
if newValue >= 10 then --The amount that you want to give badge at.
BadgeService:AwardBadge(yourBadgeIdHere)
end
end)
The first thing we should do, is index our services so that we know what to index exactly. But for now, we can just index the BadgeService:
local BadgeService = game:GetService("BadgeService")
Next up, we’re gonna add a PlayerAdded event, which will fire whenever a player joins the current server and also give them their stats:
local BadgeService = game:GetService("BadgeService")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Parent = leaderstats
end)
Now, we’re gonna find the leaderstats using the FindFirstChild Instance and also check to see if the current player has met the correct requirements to be awarded the badge using the IntValue.Changed function (Not the IntValue.Value.Changed function:)
local BadgeService = game:GetService("BadgeService")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Parent = leaderstats
repeat wait() until player:FindFirstChild("leaderstats") ~= nil
player.leaderstats.Kills.Changed:Connect(function()
if player.leaderstats.Kills.Value >= 10 then
BadgeService:AwardBadge(BadgeId, player.UserId)
print("Badge awarded to"..player.Name.."!")
end
end)
end)
BadgeId is just a placeholder for the Badge’s ID which can be located in your Game Explorer > Badges > Right Click Badge > Copy ID. Hope this helps! (This is also my first explanation)
Just use an if statement for the player’s kill value.
example :
if kill.Value >= (value) then
--code
end
--or
local badgeserv = game:GetService("BadgeService")
local badgeid = -- your badge id
Kills:GetPropertyChangedSignal("Value"):Connect(function(value)
if value >= (your amount) then
BadgeService:AwardBadge(badgeid)
end
end)
@JackscarIitt There is no reason to do repeat wait() until player:FindFirstChild("leaderstats") ~= nil, you should be doing player:WaitForChild("leaderstats"). The IntValue.Changed event gives the new value as the first parameter so you do not have to write the path again when checking.