Ad
Log in to vote
0

I am trying to make this give out a badge when youwin the mega jackpot but it wont give it out?

Asked by 15 days ago
`machine.SuperJPSensor.Touched:Connect(function(hit) -- Registers the ball reaching the Mega Jackpot hole
    if hit.Name == "Neptune_Ball" then
        muteMusic()
        local BadgeService = game:GetService("BadgeService")

        local function awardBadge(player, badgeId)
            -- Fetch badge information
            local success, badgeInfo = pcall(function()
                return BadgeService:GetBadgeInfoAsync(badgeId)
            end)

            if success then
                -- Confirm that badge can be awarded
                if badgeInfo.IsEnabled then
                    -- Award badge
                    local success, result = pcall(function()
                        return AwardBadge(game.Players:FindFirstChild(machine.CardReader.GameInfo.Player.Value), 2126911393)
                    end)

                    if not success then
                        -- the AwardBadge function threw an error
                        warn("Error while awarding badge:", result)
                    elseif not result then
                        -- the AwardBadge function did not award a badge
                        warn("Failed to award badge.")
                    end
                end
            else

        warn("Error while fetching badge info: " .. badgeInfo)
            end
        end
        machine.Particle.ParticleEmitter.Enabled = true
        sounds.MonsterJackpot2:Play()
        wait(2)
        sounds.MonsterDropMonsterJackpotSong:Play()
        ticketOut(machine.MegaJackpotScreen.Value.Value)
        for i = 1, 200 do
            machine.MegaJackpotScreen.SurfaceGui.Enabled = true
            for _,a in pairs(SideLights:GetChildren()) do a.SurfaceLight.Enabled = true; a.Material = Enum.Material.Neon end
            wait(0.1)
            for _,a in pairs(SideLights:GetChildren()) do a.SurfaceLight.Enabled = false; a.Material = Enum.Material.SmoothPlastic end
            machine.MegaJackpotScreen.SurfaceGui.Enabled = false
            wait(0.1)
        end
        machine.MegaJackpotScreen.Value.Value = MegaJPDefault
        for _,a in pairs(SideLights:GetChildren()) do a.SurfaceLight.Enabled = true; a.Material = Enum.Material.Neon end
        for i = 2, 0, -0.2 do
            sounds.MonsterJackpot2.Volume = i
            wait(0.1)
        end
        sounds.MonsterDropMonsterJackpotSong:Stop()
        machine.Particle.ParticleEmitter.Enabled = false
    end
end)`

game.Players:FindFirstChild(machine.CardReader.GameInfo.Player.Value is the player playing the game

0
You could just use a teleport script to teleport them to a part that gives badge on touch. That would make it easier probably VipDanT 0 — 15d
0
That would be stupid because you get 5 plays per swipe cbeebiespoo -5 — 15d
0
I have fixed my answer sleazel 1282 — 15d

1 answer

Log in to vote
0
Answered by
sleazel 1282 Moderation Voter
15 days ago
Edited 15 days ago

So You are declaring the awardBadge function (with the lowercase a), but You never call it. On top of that it is rather unfeasible to declare it inside the anonymous touched function. Do not nest function declarations, unless You really really know what You are doing.

The second problem is at the AwardBadge call (with the upppercase A). AwardBadge is the function of BadgeService and should be called like this BadgeService:AwardBadge(...)

Here is Your script:

local BadgeService = game:GetService("BadgeService")

local function awardBadge(player, badgeId)
            -- Fetch badge information
            local success, badgeInfo = pcall(function()
                return BadgeService:GetBadgeInfoAsync(badgeId)
            end)

            if success then
                -- Confirm that badge can be awarded
                if badgeInfo.IsEnabled then
                    -- Award badge
                    local success, result = pcall(function()
                        return BadgeService:AwardBadge(player,badgeId) --use passed arguments
                    end)

                    if not success then
                        -- the AwardBadge function threw an error
                        warn("Error while awarding badge:", result)
                    elseif not result then
                        -- the AwardBadge function did not award a badge
                        warn("Failed to award badge.")
                    end
                end
            else

        warn("Error while fetching badge info: " .. badgeInfo)
            end
end


machine.SuperJPSensor.Touched:Connect(function(hit) -- Registers the ball reaching the Mega Jackpot hole
    if hit.Name == "Neptune_Ball" then
        muteMusic()
    --add this line, and pass arguments here
--error fixed
    awardBadge(game.Players:FindFirstChild(machine.CardReader.GameInfo.Player.Value), 2126911393) 
       machine.Particle.ParticleEmitter.Enabled = true
        sounds.MonsterJackpot2:Play()
        wait(2)
        sounds.MonsterDropMonsterJackpotSong:Play()
        ticketOut(machine.MegaJackpotScreen.Value.Value)
        for i = 1, 200 do
            machine.MegaJackpotScreen.SurfaceGui.Enabled = true
            for _,a in pairs(SideLights:GetChildren()) do a.SurfaceLight.Enabled = true; a.Material = Enum.Material.Neon end
            wait(0.1)
            for _,a in pairs(SideLights:GetChildren()) do a.SurfaceLight.Enabled = false; a.Material = Enum.Material.SmoothPlastic end
            machine.MegaJackpotScreen.SurfaceGui.Enabled = false
            wait(0.1)
        end
        machine.MegaJackpotScreen.Value.Value = MegaJPDefault
        for _,a in pairs(SideLights:GetChildren()) do a.SurfaceLight.Enabled = true; a.Material = Enum.Material.Neon end
        for i = 2, 0, -0.2 do
            sounds.MonsterJackpot2.Volume = i
            wait(0.1)
        end
        sounds.MonsterDropMonsterJackpotSong:Stop()
        machine.Particle.ParticleEmitter.Enabled = false
    end
end)

This code is a bit messy, so idk it it will work. And Ceebeebies is not poo, I LOVE it :)

0
the celebration works just wont hand the badge out cbeebiespoo -5 — 15d
Ad

Answer this question