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?
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)
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)
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)