Как постоянно проверять, есть ли у игрока значок

Я делаю игру типа «найди значки», и у меня возникла проблема с моим индексом/инвентарем.

По сути, сценарий находит каждого дочернего элемента папки в рабочей области, а затем дублирует шаблон для каждого значка в рабочей области и обновляет текст в соответствии со строковыми значениями, назначенными пчелам. В углу есть небольшой индикатор, который сообщает вам, есть ли у вас значок или нет.

Однако я заметил, что он вообще не обновляет пользовательский интерфейс, даже после того, как вы соберете пчелу. Он будет обновляться только после сброса персонажа. Прикреплю видео, если объяснение не имеет смысла.

https://www.youtube.com/watch?v=1J_PDL9URmU

Вот мой код

      local BadgeService = game:GetService("BadgeService")
local player = game:GetService("Players").LocalPlayer
local UserID = player.UserId

for _,bee in pairs(workspace.Bees:GetChildren()) do
    local template = game:WaitForChild("ReplicatedStorage").BeeTemplate:Clone()
    local BadgeId = bee.BadgeId.Value
    template.Name = bee.Name
    template.BeeName.Text = bee.Name
    template.Parent = script.Parent.items
    template.ImageLabel.Image = bee.Decal.Texture
    template.Description.Value = bee.Description.Value
    template.Hint.Value = bee.Hint.Value
    template.ID.Value = bee.BadgeId.Value
    template.Location.Value = bee.Location.Value
    
    if bee.Difficulty.Value == "Freebie" then
        template.BeeDifficulty.TextColor3 = Color3.fromRGB(255, 255, 255)
        template.BeeDifficulty.Text = bee.Difficulty.Value
        template.LayoutOrder = -6
    elseif bee.Difficulty.Value == "Easy" then
        template.BeeDifficulty.TextColor3 = Color3.fromRGB(93, 255, 93)
        template.BeeDifficulty.Text = bee.Difficulty.Value
        template.LayoutOrder = -5
    elseif bee.Difficulty.Value == "Medium" then
        template.BeeDifficulty.TextColor3 = Color3.fromRGB(255, 152, 48)
        template.BeeDifficulty.Text = bee.Difficulty.Value
        template.LayoutOrder = -4
    elseif bee.Difficulty.Value == "Hard" then
        template.BeeDifficulty.TextColor3 = Color3.fromRGB(255, 57, 57)
        template.BeeDifficulty.Text = bee.Difficulty.Value
        template.LayoutOrder = -3
    elseif bee.Difficulty.Value == "Impossible" then
        template.BeeDifficulty.TextColor3 = Color3.fromRGB(149, 20, 20)
        template.BeeDifficulty.Text = bee.Difficulty.Value
        template.LayoutOrder = -2
    elseif bee.Difficulty.Value == "Secret" then
            template.BeeDifficulty.TextColor3 = Color3.fromRGB(39, 0, 77)
            template.BeeDifficulty.Text = bee.Difficulty.Value
        template.LayoutOrder = -1
    end 
        if BadgeService:UserHasBadgeAsync(UserID, BadgeId) then
            template.Owned.BackgroundColor3 = Color3.fromRGB(75, 255, 75)
            else template.Owned.BackgroundColor3 = Color3.fromRGB(255, 105, 105)
    end
end

Я попытался поместить «if BadgeService:UserHasBadgeAsync» в конец цикла while true do, но он загрузит только одну пчелу, а не загрузит их все. Я также попытался поместить весь скрипт в цикл while true do, но он продолжает повторно добавлять одних и тех же пчел в индекс, пока их не станет слишком много для Studio.

0 ответов

Другие вопросы по тегам