So I got a server script, it gives you a tool when you got a specific badge, the error is:
And the script is:
local BadgeService = game:GetService("BadgeService")
local Tool = game:GetService("ServerStorage"):WaitForChild("Chocolate Milk")
local BadgeId = 1111111111
game.Players.PlayerAdded:Connect(function(player)
if BadgeService:UserHasBadgeAsync(player.UserId,BadgeId) then
Tool:Clone().Parent = player.Backpack
Tool:Clone().Parent = player.StarterGear
end
end)
I don’t see any issues with the current code. You should change the badge id to an actual badge id so it doesn’t check for something that doesn’t exist (probably the issue you’re seeing).
local BadgeService = game:GetService("BadgeService")
local Tool = game:GetService("ServerStorage"):WaitForChild("Chocolate Milk")
local BadgeId = 1111111111
game.Players.PlayerAdded:Connect(function(player)
if BadgeService:UserHasBadgeAsync(player.UserId,BadgeId) then
local ClonedTool = Tool:Clone()
CloneTool.Parent = player.Backpack
end
end)
The item given in the clone event goes from the inventory after the character respawns and that’s not the main issue, the main issue is UserHasBadgeAsync error
Just at least so it doesn’t break the whole script when encountering this error:
local BadgeService = game:GetService("BadgeService")
local Tool = game:GetService("ServerStorage"):WaitForChild("Chocolate Milk")
local BadgeId = 0
game.Players.PlayerAdded:Connect(function(player)
pcall(function()
if BadgeService:UserHasBadgeAsync(player.UserId,BadgeId) then
Tool:Clone().Parent = player.Backpack
Tool:Clone().Parent = player.StarterGear
end
end)
end)
Just wrap the network call inside pcall the cloning should go outside.
local BadgeService = game:GetService("BadgeService")
local Tool = game:GetService("ServerStorage"):WaitForChild("Chocolate Milk")
local BadgeId = 0
game.Players.PlayerAdded:Connect(function(player)
local res, err = pcall(function() return BadgeService:UserHasBadgeAsync(player.UserId,BadgeId) end)
if not res then warn(err) return end --Output error if one occurred.
Tool:Clone().Parent = player.Backpack --May need 'WaitForChild'.
Tool:Clone().Parent = player.StarterGear --May also need 'WaitForChild'.
end)
Use a pcall and retry, this is a roblox issue
All type of web requests should be done with safe calls because there can be network issues, unlike server services functions and methods