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
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)
Adding to what mentioned above,
you should always wrap such calls in pcalls
. Example:
local success,result = pcall(function()
return game:GetService("BadgeService"):UserHasBadgeAsync(Player.UserId,BadgeID)
end)
if success then
if not result then
--award him here.
end
end
it didn’t work i putted the print thing it worked, but the badge still didnt award i do not know why
As @Valkyrop said you should check if the player first has a badge so to do this I would do it like this:
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
for _,v in pairs(game:GetService("Players"):GetPlayers()) do
local success,hasBadge = pcall(function() -- pcall so it returns the value and if there was an error
return game:GetService("BadgeService"):UserHasBadgeAsync(v.UserId,BadgeID) -- Check if the player has the badge using RobloxAPI
end)
if success and not hasBadge then
game:GetService("BadgeService"):AwardBadge(v.UserId, BadgeID) -- No error happened and the player does not own the badge so you can award it
end
end
end
end)
I just realised that the badge was in the incorrect place. Thank you for the help.