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)
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)
game.Workspace.DescendantRemoving:Connect(function(Descendant) -- Checks whenever a Descendant is removed from workspace.
if Descendant.Name == "YourBallName" then
-- Code
end
end)
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)
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)
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.
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)
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)