Tool isnt cloning into players backpack if player has required badge

Hey dev forume peeps, got a little bit of a scripting issue that im trying to resolve. As you can see from the topic i have a badge checking script in which checks if the player has a badge and then runs script if the player does end up having the badge.
.
What im trying to do with it, is making it so it would give you a tool if you have the badge

local badgeService = game:GetService("BadgeService")
local myBadge = 2152919439
local item = game.ServerStorage:WaitForChild("ClassicSword")
local backpack =  game.Players.LocalPlayer.Backpack


game.Players.PlayerAdded:Connect(function(player)
	if badgeService:UserHasBadgeAsync(player.UserId, myBadge) then
		item:Clone()
		item.Parent = backpack
	end

end)

Problem is it seems to not be cloning the tool into the players backpack and i dont know why. What have i done wrong and what can i do to resolve this issue?

Thanks in advanced

3 Likes

You’re parenting the tool in ServerStorage, not the cloned instance. Turn item:Clone() into a variable and parent that.

local ClonedItem = item:Clone()
ClonedItem.Parent = backpack

Or parent the cloned item right away.

item:Clone().Parent = backpack
3 Likes

Your backpack variable probably wont work in the script because it is using LocalPlayer. It should be like this:

game.Players.PlayerAdded:Connect(function(player)
	if badgeService:UserHasBadgeAsync(player.UserId, myBadge) then
		local backpack = player.Backpack
		local ClonedItem = item:Clone() --Like ZynAstral said, you need to make this a variable
		ClonedItem.Parent = backpack
	end
end)

Am i doing this correctly?

local badgeService = game:GetService("BadgeService")
local myBadge = 2152919439
local item = game.ServerStorage:WaitForChild("ClassicSword")

game.Players.PlayerAdded:Connect(function(player)
	if badgeService:UserHasBadgeAsync(player.UserId, myBadge) then
		local backpack = player.Backpack
		local ClonedItem = item:Clone()
		ClonedItem.Parent = backpack
	end
end)

Should be. Make sure it’s a server script like poly said.

Then thats pretty odd, still seems to not clone the tool into my backpack. (i am testing in game so i do have the badge)

1 Like

Add a CharacterAdded event aswell.

local badgeService = game:GetService("BadgeService")
local myBadge = 2152919439
local item = game.ServerStorage:WaitForChild("ClassicSword")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if badgeService:UserHasBadgeAsync(player.UserId, myBadge) then
			local backpack = player.Backpack
			local ClonedItem = item:Clone()
			ClonedItem.Parent = backpack
		end
	end)
end)
2 Likes

Oops, sorry for the late response. It should be like that.

2 Likes

ah ok seems like that was the issue, thanks mate

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.