Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can some on help me with this script? I don't know where to put my badge ID.

Asked by 9 years ago
function Create(ty)
    return function(data)
        local obj = Instance.new(ty)
        for k, v in pairs(data) do
            if type(k) == 'number' then
                v.Parent = obj
            else
                obj[k] = v
            end
        end
        return obj
    end
end



function GetCurrentNotifyGuis(player)
    local guis = {}
    for i,v in pairs(player.PlayerGui:GetChildren()) do
        if v.Name == "Notification" then
            if v:findFirstChild("NotifyFrame") and v.NotifyFrame:IsA("Frame") then
                local guiInfo = {}
                table.insert(guiInfo,v)
                if  v.NotifyFrame.Position.Y.Offset == -120 then
                    table.insert(guiInfo,1)
                elseif v.NotifyFrame.Position.Y.Offset == -190 then
                    table.insert(guiInfo,2)
                end
                table.insert(guis,guiInfo)
            end
        end
    end
    return guis
end

function getGui(title,message,image,timeout,callback)
    local gui = Create'ScreenGui'{
        Name = "Notification";
        Create'Frame'{
            Size = UDim2.new(0, 200, 0, 67);
            Style = Enum.FrameStyle.RobloxRound;
            Name = "NotifyFrame";
            Position = UDim2.new(1, 0, 1, -120);
            Create'ImageLabel'{
                Image = image;
                ZIndex = 2;
                Size = UDim2.new(0.26, 0, 0.95, 0);
                Name = "image";
                BackgroundTransparency = 1;
            };
            Create'ImageLabel'{
                Image = "http://www.roblox.com/asset/?ID=115685608";
                ZIndex = 3;
                Size = UDim2.new(0.26, 0, 0.95, 0);
                Name = "imageoverlay";
                BackgroundTransparency = 1;
                BorderSizePixel = 1;
            };

            Create'TextLabel'{
                Text = title;
                Size = UDim2.new(0.69, 0, 0.3, 0);
                TextColor3 = Color3.new(1, 1, 1);
                TextWrap = true;
                Font = Enum.Font.ArialBold;
                Name = "Title";
                Position = UDim2.new(0.26, 0, 0, 0);
                BackgroundTransparency = 1;
                TextScaled = true;
            };
            Create'TextLabel'{
                Text = message;
                Size = UDim2.new(0.69, 0, 0.2, 0);
                TextColor3 = Color3.new(1, 1, 1);
                TextWrap = true;
                Name = "Message";
                Position = UDim2.new(0.26, 0, 0.6, 0);
                BackgroundTransparency = 1;
                TextScaled = true;
            };
            Create'ImageButton'{
                Image = "rbxasset://textures/ui/CloseButton.png";
                ZIndex = 4;
                Size = UDim2.new(0, 20, 0, 20);
                BackgroundTransparency = 1;
                Name = "Close";
                Position = UDim2.new(0.925, 0, -0.1, 0);
            };
            Create'TextButton'{
                ZIndex = 3;
                Name = "CloseOverlay";
                Text = "";
                Size = UDim2.new(1, 0, 1, 0);
                BackgroundTransparency = 1;
            };
        };
    };
    gui.NotifyFrame.CloseOverlay.MouseButton1Up:connect(function ()
        if callback then
            callback()
        end
        gui.NotifyFrame:TweenPosition(UDim2.new(1,0,1,gui.NotifyFrame.Position.Y.Offset),"Out","Linear",0.25,true,nil)
        wait(1)
        gui:Destroy()
    end)
    gui.NotifyFrame.Close.MouseButton1Up:connect(function () 
        if callback then
            callback()
        end
        gui.NotifyFrame.Close.Image = "rbxasset://textures/ui/CloseButton.png" 
        gui.NotifyFrame:TweenPosition(UDim2.new(1,0,1,gui.NotifyFrame.Position.Y.Offset),"Out","Linear",0.25,true,nil) 
        wait(1)
        gui:Destroy()
    end)
    gui.NotifyFrame.Close.MouseButton1Down:connect(function ()
        gui.NotifyFrame.Close.Image = "rbxasset://textures/ui/CloseButton_dn.png" 
    end)
    gui.NotifyFrame.Close.MouseLeave:connect(function ()
        gui.NotifyFrame.Close.Image = "rbxasset://textures/ui/CloseButton.png"
    end)
    delay(timeout,function () 
        if gui:findFirstChild("NotifyFrame") then
            gui.NotifyFrame:TweenPosition(UDim2.new(1,0,1,gui.NotifyFrame.Position.Y.Offset),"Out","Linear",0.25,true,nil)  
            wait(1)
            gui:Destroy()
        end
    end)
    return gui
end

function GetPlayerFromID(Id)
    local p = nil
    for i,v in pairs(game.Players:GetPlayers()) do
        if v.userId == Id then
            if string.sub(v.Name,1,6) ~= "Guest " then
                p = v
            end 
        end
    end
    return p
end

local SoundEnabled = true

_G.AwardBadge = function (userId,badgeId)
    if type(userId) == "number" and type(badgeId) == "number" then 
        if GetPlayerFromID(userId) ~= nil then
            local bInfo = game:GetService("MarketplaceService"):GetProductInfo(badgeId)
            if bInfo.AssetTypeId == 21 then
                if game:GetService("BadgeService"):UserHasBadge(userId,badgeId) ~= true then
                    for _,v in pairs(game.Players:GetPlayers()) do
                        local guis = GetCurrentNotifyGuis(v)
                        if #guis ~= 0 then
                            for i = 1,#guis do
                                if guis[i][2] == 1 then
                                    guis[i][1].NotifyFrame:TweenPosition(UDim2.new(1,-200,1,-190),"Out","Linear",0.25,true,nil)
                                else
                                    guis[i][1].NotifyFrame:TweenPosition(UDim2.new(1,0,1,-190),"Out","Linear",0.25,true,nil)
                                    game:GetService("Debris"):AddItem(guis[i][1],0.25)
                                end
                            end
                        end
                        local bName = bInfo.Name
                        local bImage = "http://www.roblox.com/Game/Tools/ThumbnailAsset.ashx?fmt=png&wd=110&ht=110&aid="..badgeId
                        local gui = getGui(GetPlayerFromID(userId).Name.." got a badge!",[["]]..bName..[["]],bImage,15,nil)
                        gui.Parent = v.PlayerGui
                        gui.NotifyFrame:TweenPosition(UDim2.new(1,-200,1,-120),"Out","Quad",0.25,true,nil)
                    end
                    if SoundEnabled == true then
                        SoundEnabled = false
                        script.BadgeSound:Play()
                        wait(1)
                        SoundEnabled = true
                    end
                    game:GetService("BadgeService"):AwardBadge(userId,badgeId)
                end
            end
        end
    end
end

1 answer

Log in to vote
1
Answered by 9 years ago

This is simple. _G (Global) Is before AwardBadge function, so you can use it in any script:

It would be pretty much this if you are using BADGE Got hit:

if script.Parent:findFirstChild("Humanoid") ~= nil then
_G.AwardBadge(game.Players:GetPlayer(script.Parent.Parent.Name).userId, yourBadgeIdHere)
end

Hope it helped! Thanks, marcoantoniosantos3

Ad

Answer this question