How do I make it so that the model on the right appears instead of the model on the left when a player hasn’t unlocked a certain badge? Any help would be greatly appreciated!
hat_models.rbxm (7.8 KB)
How do I make it so that the model on the right appears instead of the model on the left when a player hasn’t unlocked a certain badge? Any help would be greatly appreciated!
hat_models.rbxm (7.8 KB)
Bump
On the client:
local player = game.Players.LocalPlayer
local userHasBadgeFunc = ... -- whatever the remote function is
local BADGE_ID = 000000 -- change for badge id
local ownsBadge = userHasBadgeFunc:InvokeServer(BADGE_ID)
if ownsBadge then
print(player, "has the badge")
-- Make hat visible
else
print(player, "does not have the badge")
-- Make hat ghost effect / whatever you're doing
end
On the server:
local BadgeService = game:GetService("BadgeService")
local func = ... -- Whatever the remote function is
func.OnServerInvoke = function(player, badgeId)
return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
end
(UserOwnsBadge is now deprected)
To add to this, UserHasBadge
still works and can be used to avoid communicating with the server through the RemoteFunction
:
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local BadgeId = 0 --your badge id
--not using async
local OwnsBadge = BadgeService:UserHasBadge(Player.UserId, BadgeId)
print(OwnsBadge)
Considering it’s deprecated status I would advise against using it as its functionality could be removed at any given moment which would result in the script breaking.
Instead of a RemoteFunction you could simply handle everything inside of a server script with the PlayerAdded event.
The point was to change the visibility of the hat, which wouldn’t work server-sided