Hello. When attempting to script event with a lil help from devforum, I noticed it wont give the badge.
Also I want it so the gifts only disappears on the players screen when they clicked it, not others.
I run this on serverscript.
local BadgeID = 2113630409
local GiftHandlers = {"Handle1", "Handle2", "Handle3", "Handle4", "Handle5"}
local IsAllTransparent = true
local function CheckGifts(plr)
for i, Gifts in ipairs(script.Parent:GetChildren()) do
if table.find(GiftHandlers, Gifts.Name) and Gifts.Transparency == 0 then
IsAllTransparent = false
end
end
if IsAllTransparent == true then
local b = game:GetService("BadgeService")
if b:UserHasBadgeAsync(plr, BadgeID) == false then
b:AwardBadge(plr.userId, BadgeID)
end
end
wait(0.1)
IsAllTransparent = true
end
for i, Gifts in ipairs(script.Parent:GetChildren()) do
if table.find(GiftHandlers, Gifts.Name) then
Gifts:FindFirstChild("ClickDetector").MouseClick:Connect(function(plr)
Gifts.Transparency = 1
Gifts.CanCollide = false
CheckGifts(plr)
end)
end
end
It probably isn’t awarding the badge because your “IsAllTransparent” variable might be set to false, since your for loop above the check is changing the variable to “false” whenever it finds one of the “Gift’s” transparency 0.
As for making the gift disappear on only the local player’s screen, you’ll have to handle the gift’s transparency in a local script.
Well, you would have to use a remote event to check if it is only on the client. If it is only changed on the client, the server will not see the change, therefore, making them never receive the badge.
Ok uh, I rewrote the script. Pretty sure I’m gonna have errors.
The localscript:
local GiftHandlers = {"Handle1", "Handle2", "Handle3", "Handle4", "Handle5"}
local remote = game.ReplicatedFirst.event
local IsAllTransparent = true
local function CheckGifts(plr)
for i, Gifts in ipairs(script.Parent:GetChildren()) do
if table.find(GiftHandlers, Gifts.Name) and Gifts.Transparency == 0 then
IsAllTransparent = false
end
end
end
for i, Gifts in ipairs(script.Parent:GetChildren()) do
if table.find(GiftHandlers, Gifts.Name) then
Gifts:FindFirstChild("ClickDetector").MouseClick:Connect(function(plr)
Gifts.Transparency = 1
Gifts.CanCollide = false
CheckGifts(plr)
end)
end
end
for i, Gifts in ipairs(script.Parent:GetChildren()) do
if table.find(GiftHandlers, Gifts.Name) and Gifts.Transparency == 1 then
IsAllTransparent = true
end
end
if IsAllTransparent == true then
remote:FireServer()
end
The ServerScript:
local BadgeID = 2113630409
local plr = game.Players
if game.ReplicatedFirst.event:FireClient() then
local b = game:GetService("BadgeService")
if b:UserHasBadgeAsync(plr, BadgeID) == false then
b:AwardBadge(plr.userId, BadgeID)
end
end
I think the issue is the time the remoteevent gets fired is when ‘IsAllTransparent’ is true, but it’s not in a loop, so when the script goes down to that line, it checks if it’s true or false, but the reason you don’t get the badge may can be because at that time ‘IsAllTransparent’ is false, try to make it inside of a loop.
game.ReplictedFirst.event.OnServerEvent:Connect(function(player)
if not badgeService:UserHasBadgeAsync(player.UserID, BadgeID) then
badgeService:AwardBadge(player.UserID, BadgeID)
end)