Hello! I’m trying to something I thought would be rather simple with badges but it turned out I’m having issues with it. Basically I wanted to make something where lets say, we have a badge and a part. If the player has the badge, the part turns green, if not, the part stays the same. HOWEVER I need to make this local as well. Which is why I made this in a local script. I tried making it work but it doesn’t register any errors but the script doesn’t turn the brick green when I have the badge, what am I doing wrong here?
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
UseHasBadgeAsync can be called only from a ServerScript, it says it on the wiki page
Best bet would to either invoke the server and return the parts or check the badges on the server and fire a RemoteEvent telling the client what parts to turn green and execute from there.
Example Implementation:
-- This method is using a RemoteEvent
[Variables]
-- You can have a dictionary of parts as keys and the value be the BadgeId
-- An alternative would be to have a folder filled withparts and their name being -
-- the Id and get the folders children using Instance:GetChildren()
[Player Event]
-- You then would want to use a PlayerAdded event from the service "Players"
-- In the event you would need to check if they have the badges, in a loop
[Firing Client]
-- Personally I'd make a new array so I can easily send the data over
-- Once you fire the RemoteEvent using the sent data accordingly
--server script
local BadgeService = game:GetService('BadgeService')
local Players = game:GetService('Players')
local Player = Players.LocalPlayer
if BadgeService:UserHasBadgeAsync(Player.UserId, PlaceHolderID) then
Color = Color3.new(91, 154, 76)
game.ReplicatedStorage.RemoteFunction:FireClient(Player,Color)
end
--local script
game.ReplicatedStorage.RemoteFunction.OnClientEvent:Connect(function(color)
script.Parent.Color = color
end