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

I want to make a quick system where if a player has a badge, a part turns green on their client. However I’ve already tried multiple solutions such as trying to make the server detect it and then it’ll be sent back to the client, but it doesn’t work. I know I can’t use local scripts and I tried making it a sever script but I really don’t know where to go from there either.

local BadgeService = game:GetService('BadgeService')
local Players = game:GetService('Players')
local Player = Players.LocalPlayer


if BadgeService:UserHasBadgeAsync(Player.UserId, PlaceHolderID) then
	script.Parent.Color = Color3.new(91, 154, 76)
end
2 Likes

You would just need to check if the player has the badge on the server. I’m assuming you want it to change color when the player joins the game, so you would use PlayerAdded, then check if they have the badge and use FireClient to the tell the client to change the color of the part.

2 Likes

That’s what I’ve been told multiple times but I don’t know how I’d write it at all.

2 Likes

Use Color3.fromRGB instead of .new.

2 Likes

So I went ahead and tried to fix that but now I get this, I don’t know if that’s unrelated but it happens now.image

1 Like

Add a wait(0.1) in there before the if statement, you’re calling too fast.

2 Likes

I tried that and it still has the exact same result with the same error.

1 Like

Increase the wait time to 1 or 2, fromRGB wouldn’t do this

1 Like

I changed it to wait (10) clearly there is something else wrong and what do you mean “fromRGB wouldn’t do this?”

1 Like

Changing the script from Color3.new to Color3.fromRGB would not throw this error, change it back and see what I mean.

1 Like

Except where the error has happened before we changed it.

1 Like

First of all make the check on a server script and then send a remote event to the client. Once the client has received the remote event use Color3.fromRGB() instead. Why should the check be on the server you may ask and that is because else a player can hack it and get that color without the badge

1 Like

I tried to do this but I don’t understand, additionally I added the function (ColorFunction) and yet it still doesn’t work.

1 Like

You have to fire the server from the client. Also, no need to have a “player” parameter

1 Like

I removed that and it has the same error.

1 Like

Is the script you showed client or server sided?

You told me to put it back in client so I threw into the original brick I started with.

So… is that server or client? I don’t understand.

It’s just a normal script I don’t know how to tell the difference anymore I feel so lost now.

Okay, there’s your problem. You cannot call LocalPlayer on a normal script, use PlayerAdded with a “plr” parameter instead.