I am making a leaderboard for the number of times people ride roller coasters in my game, and I am trying to add a way to give players badges when they reach a certain level. The levels I am going to add are 50, 100, 200, 300, but I can't even get the first one to work.
Code:
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Coasters = Instance.new("IntValue") Coasters.Name = "Coasters" Coasters.Parent = leaderstats local BadgeService = game:GetService("BadgeService") local badgeid = --BadgeID Here Coasters:GetPropertyChangedSignal("Value"):Connect(function(value) if value >= 50 then BadgeService:AwardBadge(badgeid) end end) end)
I immediately saw the problem, actually 2 problems!
Here's your new code:
game:GetService("Players").PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Coasters = Instance.new("IntValue") Coasters.Name = "Coasters" Coasters.Value = 0 Coasters.Parent = leaderstats local BadgeService = game:GetService("BadgeService") local badgeid = 0 coroutine.resume(coroutine.create(function() -- Corountine loop so we don't disturb code below it! while wait() do Coasters:GetPropertyChangedSignal("Value"):Connect(function() if Coasters.Value >= 50 then BadgeService:AwardBadge(badgeid) end end) end end)) end)
hey you! have you ever heard of enes? if you are in trouble, better call enes!