[SOLVED] Badge giver script not working

Hello! I am trying to make a game with a ball. So I wanted to make a badge when the ball falls out of the map. I did exactly the script but the ball disappears and I do not know why.

So when It falls to the void I want it to like award the players the badge and the ball just disappears. I assume that the ball destroyed itself, and not like it falled to the void.

1st script:

local ball = game.Workspace.ball


if ball:Destroy() then
	   game.Players.PlayerAdded:Connect(function(player)
		game:GetService("BadgeService"):AwardBadge(player.UserId, 2127919489)
	end)
end

2nd script:

local ball = game.Workspace.ball
local BadgeID = 2127919489
local void = game.Workspace.a
local void2 = game.Workspace.b
local void3 = game.Workspace.c
local void4 = game.Workspace.d

ball.Touched:Connect(function(touch)
	if touch.Parent == void then -- i added one of it cuz ill work on this later
		ball:Destroy()
		game.Players.PlayerAdded:Connect(function(p)
			game:GetService("BadgeService"):AwardBadge(p.UserId, BadgeID)
		end)
		
		
	end
end)
1 Like

If I understand correctly what you’re trying to do is give a badge to every player who joins after the ball has fallen into the void right? May you elaborate a bit more or just explain exactly what you’re trying to do so I can guide you through all of this? (This is my first reply on the dev forums so probably won’t be my best, but I will try my best)

Try replacing

if ball:Destroy() then

With

if ball == nil or ball.Parent == nil then
game.Workspace.DescendantRemoving:Connect(function(Descendant) -- Checks whenever a Descendant is removed from workspace.
if Descendant.Name == "YourBallName" then
-- Code
end
end)

Yes, I am doing that, If the ball falls down to the void.

Code doesn’t work, It doesn’t award the badge to the player.

You should then do something along the lines of

local ball = game:GetService("Workspace").ball

game:GetService("Workspace").DescendantRemoving:Connect(function(descendant) --RBXScriptSignal that gets fired when something is removed from workspace
    if descendant == ball then -- The object that is being removed is the ball
        -- Do what you want
    end
end)

do you want to give the badge to all the players?

game.Workspace.DescendantRemoving:Connect(function(Descendant) -- Checks whenever a Descendant is removed from workspace.
if Descendant.Name == "YourBallName" then
for i,v in pairs(game.Players:GetPlayers()) -- Looping through all of the players.
if game:GetService("BadgeService"):UserHasBadge(v.UserId,BadgeID) then return end -- Checking if the user already has the badge.
game:GetService("BadgeService"):AwardBadge(v.UserId,BadgeID) -- Awarding the Badge to all of the players.
end
end
end)

doesn’t work the ball just gets stuck at the void

The RBXScriptSignal only executes when it is destroyed so if you have something blocking the ball from falling in the void I would recommend removing it.

the ball lags out and doesnt even give a badge, i disabled any castshadow, massless and deleted those 4 parts in the game

Can you show the new code? So I can see what’s happening?

I’m sorry but this doesn’t really help me to know what’s going on since I need to see the code but not the Script location

wait let me test it out first hold on

https://gyazo.com/5dc426b0c57e2b622f534124b8cd9d1a

So you want the last player that touched the ball that threw it into the void to get a badge is that right?

here is the code

local ball = game:GetService("Workspace").ball
local BadgeID = 2127919489

game:GetService("Workspace").DescendantRemoving:Connect(function(descendant) --RBXScriptSignal that gets fired when something is removed from workspace
	if descendant == ball then -- The object that is being removed is the ball
		game.Players.PlayerAdded:Connect(function(p)
			game:GetService("BadgeService"):AwardBadge(p.UserId, BadgeID)
		end)
	end
end)

yes it is, and i want it the badge to be rewarded to everyone

This should do the job

local ball = game:GetService("Workspace").ball

game:GetService("Workspace").DescendantRemoving:Connect(function(descendant) --RBXScriptSignal that gets fired when something is removed from workspace
    if descendant == ball then -- The object that is being removed is the ball
        for _,v in pairs(game:GetService("Players"):GetPlayers()) do
            game:GetService("BadgeService"):AwardBadge(v.UserId, BadgeID)
        end
    end
end)

If the thing above didn’t work, you should try this:

local ball = game:GetService("Workspace").ball

game:GetService("Workspace").DescendantRemoving:Connect(function(descendant) --RBXScriptSignal that gets fired when something is removed from workspace
    if descendant.Name == ball.Name then -- The object that is being removed is the ball
        for _,v in pairs(game:GetService("Players"):GetPlayers()) do
            game:GetService("BadgeService"):AwardBadge(v.UserId, BadgeID)
        end
    end
end)