How to make a part change color on a client if they have a badge?

image

1 Like

What line of code is that? Should be next line in Output under that error message. It says, e.g. “line 23”

It doesn’t say one in the line.

That’s not possible, it can’t throw an error without a script invoke first. I can’t help you if you can’t find it, sorry.


This is literally all it says.

Line 6 is what I was looking for. Like I said, use PlayerAdded.

Since you have a web request that could fail (BadgeService:UserHasBadgeAsync), pcall is something your script should have.

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

Players.PlayerAdded:Connect(function(Player)
	local Sucess, Badge = pcall(function()
		return BadgeService:UserHasBadgeAsync(Player.UserId, 2124588181)
	end)
	if not Sucess then
		warn(Badge) -- It'll warn for any errors
	end
	ReplicatedStorage.ColorFunction:FireClient(Player, Color3.fromRGB(85, 255, 0))
end)

Here’s the three different types of scripts, you can tell them apart from their icons. It’s a good idea to know the difference when you need help. :slight_smile:

image

Learning References:
pcall - You need to scroll a bit down to find it. Basically, if a function inside a pcall has an error, the pcall will catch the error.
Server Scripts
Local Scripts
Module Scripts