Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

PLS HELP! I have a BadgeService problem! What should I do?

local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

local id = 2124618277

Players.PlayerAdded:Connect(function(player)
	local pumpkin = Instance.new("NumberValue")
	pumpkin.Name = "Pumpkin"
	pumpkin.Value = 0
	pumpkin.Parent = player
	
	
	while not player:FindFirstChild("PlayerGui"):FindFirstChild("ScreenGui")do wait() end
	local debounce = false
	while wait(1) do
		local Guis = player.PlayerGui.ScreenGui
		local CollectedPumpkins = pumpkin.Value
		
		if Guis then
			Guis.kutu.TextLabel.Text = ("10/"..CollectedPumpkins)
		end
	end
	--if player.Pumpkin.Value >= 10 then
	if pumpkin.Value >= 10 then
		pcall(BadgeService.AwardBadge, BadgeService, player.UserId, id)
	end
end)

I am using it but only Badge is not working. When the pumpkins is 10, it does not badge award and does not work.. What should I do?

2 answers

Here's an explanation I believe you'll find helpful, if you need anything else feel free to ask.

Explanation will be in the notes of the following script:

--[[
  It looks like you're updating it based on the value of the NumberValue, instead you could be using GetPropertyChangedSignal.

  I don't believe the id variable isn't very necessary.
]]

local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")

--[[
  I'll put these variables here if they help you.
]]

local MaxPumpkins = 10
local StartingPumpkins = 0

local function OnPlayerAdded(Player)
  local Pumpkin = Instance.new("NumberValue")
  Pumpkin.Name = "Pumpkin"
  Pumpkin.Value = StartingPumpkins
  Pumpkin.Parent = Player

  local PlayerGui = Player:WaitForChild("PlayerGui")
  Pumpkin:GetPropertyChangedSignal("Value"):Connect(function()
    if Pumpkin.Value >= MaxPumpkins then
      -- Basically, this is saying if the value is over the max pumpkins or IS the max pumpkins value, then it should reward the badge and keep the pumpkin value at max.
      Pumpkin.Value = MaxPumpkins
      BadgeService:AwardBadge(Player.UserId,2124618277)
    end
    pcall(function()
      Guis.kutu.TextLabel.Text = MaxPumpkins .. "/" .. Pumpkin.Value
    end)
  end)
end

-- Call on existing players if this script was delayed.

for index,value in pairs(Players:GetPlayers()) do
  OnPlayerAdded(value)
end

-- Create the Script Connection.

Players.PlayerAdded:Connect(OnPlayerAdded)

1 comment

0

I tried it didn't work. pcall(function() Guis.kutu.TextLabel.Text = MaxPumpkins .. "/" .. Pumpkin.Value end) end) end-- Part of it is "Guis" underlined and didn't work.

You are checking if the pumpkin's value is 10 right now. You need to check that when the value changes.

pumpkin.Changed:Connect(function()
	if pumpkin.Value >= 10 then
		 pcall(BadgeService.AwardBadge, BadgeService, player.UserId, id)
	end
end)

If that still does not work, try doing this:

	pumpkin.Changed:Connect(function()
		if pumpkin.Value >= 10 then
			 pcall(BadgeService.AwardBadge, BadgeService, player.UserId, id)
		end
	end)
    while not player:FindFirstChild("PlayerGui"):FindFirstChild("ScreenGui")do wait() end
    local debounce = false
    while wait(1) do
        local Guis = player.PlayerGui.ScreenGui
        local CollectedPumpkins = pumpkin.Value

        if Guis then
            Guis.kutu.TextLabel.Text = ("10/"..CollectedPumpkins)
        end
    end

1 comment

0

It did not happen again, it was very complicated. Can you add a friend my account is AvsarHaydar? Let's add you in the edit. Can you help?

This discussion is preserved as it was. New answers, comments, and votes are closed.