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

How to make badge give permanent gear?

Asked by 2 years ago
Edited 2 years ago

I have this badge that gives the player the Teddy Bloxpin gear, but they have to rejoin to get it. How do I make it so they get the gear as soon as they get the badge, and keep it if they die?

ServerScriptService:

local mps = game:GetService("BadgeService")
local badge_id = 2127257301

game.Players.PlayerAdded:Connect(function(player)
    if mps:UserHasBadgeAsync(player.userId, badge_id) then
        game.ServerStorage.TeddyBloxpin:Clone().Parent = player:WaitForChild("Backpack")
        game.ServerStorage.TeddyBloxpin:Clone().Parent = player:WaitForChild("StarterGear")
    end
end)

game.ReplicatedStorage.TeddyBloxpin.OnServerEvent:connect(function(player)
    game.ServerStorage.TeddyBloxpin:Clone().Parent = player:WaitForChild("Backpack")
    game.ServerStorage.TeddyBloxpin:Clone().Parent = player:WaitForChild("StarterGear")
end)

Gives Badge:

local badgeservice = game:GetService("BadgeService")
local id = (2127257301)
script.Parent.Touched:Connect(function(hit)

    if hit.Parent:FindFirstChild("Humanoid") then

        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        badgeservice:AwardBadge(plr.UserId, id)
    end
end)

local mps = game:GetService("BadgeService")

script.Parent.Touched:connect(function(plr)
    local player = game.Players.LocalPlayer
end)

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
2 years ago

Just give the player the tool when you give the badge:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        badgeservice:AwardBadge(plr.UserId, id)

        game.ServerStorage.TeddyBloxpin:Clone().Parent = player.Backpack
        game.ServerStorage.TeddyBloxpin:Clone().Parent = player.StarterGear
    end
end)
0
I get this error: Workspace.Model.Model.SecretRoom.Part.Script:21: attempt to index nil with 'Backpack' BunjiBloxxer 51 — 2y
0
"player" is nil because it's not defined. Just change it to "plr" Rare_tendo 3000 — 2y
0
It works, but it gives a million of them filling the player's inventory BunjiBloxxer 51 — 2y
0
Check if the player already owns the badge so it won't fill the entire inventory. GamerLighting23233 63 — 1y
Ad

Answer this question