local Player = game.Players.LocalPlayer
local CoinCount = Player.leaderstats:WaitForChild("Coins")
local MorphModEvent = game.ReplicatedStorage.GivePlayerMorph
local DeathCount = Player.leaderstats:WaitForChild("Deaths")
local badgeservice = game:GetService("BadgeService")
local BadgeID = script.Parent.BadgeID.Value
local SubMenu = script.Parent.CharacterSubMenu.Value
local CoinCost = script.Parent.CoinMilestone.Value
local BadgeCost = script.Parent.BadgeMilestone.Value
local DeathCost = script.Parent.DeathMilestone.Value
local LegoClick = script.Parent.ClickSound
local LegoDeny = script.Parent.DenySound
local Costumes = script.Parent.Parent.Parent.CostumeSelect
local Characters = script.Parent.Parent.Parent.CharacterSelect
local Unlocked = script.Parent.Unlocked
wait(1)
local HasBadge = badgeservice:UserHasBadgeAsync(Player.UserId, BadgeID)
script.Parent.MouseButton1Click:Connect(function()
if Unlocked.Value == true then
LegoClick:Play()
--
Costumes.Visible = true
Costumes.Active = true
--
SubMenu.Visible = true
SubMenu.Active = true
--
Costumes.Parent.Requirements.Enabled = false
Costumes.Parent.CharacterSelect.Active = false
Costumes.Parent.CharacterSelect.Interactable = false
else
print(Player.Name.. " can't use Character because they are Locked!!")
LegoDeny:Play()
end
end)
while true do
if CoinCount.Value >= CoinCost --[[and DeathCount.Value >= DeathCost]] or Player:FindFirstChild("Morphs"):FindFirstChild(""..script.Parent.Name) then
if HasBadge == true then
script.Parent.Character.ImageColor3 = Color3.fromRGB(255, 255, 255)
if not Player.Morphs:FindFirstChild(script.Parent.Name) then
MorphModEvent:FireServer(script.Parent)
print("Checking If "..Player.Name.." Has Morph")
Unlocked.Value = true
else
print(""..Player.Name.." Has Morph Already !!")
Unlocked.Value = true
end
Unlocked.Value = true
task.wait(5)
else
script.Parent.Character.ImageColor3 = Color3.fromRGB(0, 0, 0)
Unlocked.Value = false
task.wait(5)
end
else
script.Parent.Character.ImageColor3 = Color3.fromRGB(0, 0, 0)
Unlocked.Value = false
task.wait(5)
end
end
Whenever I use this script it sometimes works and sometimes doesn’t, im looking for a script that’s more optimized for checking if the player has the badge