Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make badge give permanent gear?

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

✓ Accepted answer

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)

4 comments

0

I get this error: Workspace.Model.Model.SecretRoom.Part.Script:21: attempt to index nil with 'Backpack'

0

"player" is nil because it's not defined. Just change it to "plr"

0

It works, but it gives a million of them filling the player's inventory

0

Check if the player already owns the badge so it won't fill the entire inventory.

This discussion is preserved as it was. New answers, comments, and votes are closed.