Problem with updating GUI

Hi all developers, i have a problem for my gui.

When i load the game all things are perfect(like gui, scripts) but i figured out that when i touch a duck that i don’t have it gives me the badge but the gui doesn’t update. I’m a beginner in scripting so i tried some scripts but nono of them works.

This is the local script in the GUI:

local Ducks = require(game:GetService("ReplicatedStorage").DucksUIHandler.Ducks)
local BadgeService = game:GetService("BadgeService")

for _, duck in ipairs(Ducks) do
	local duckFrame =game.ReplicatedStorage.DucksUIHandler.Template:Clone()
	duckFrame.Parent = script.Parent.Frame.Container
	duckFrame.Name = duck.ID
	duckFrame.ImageLabel.Image = "rbxthumb://type=Asset&id="..duck.imageID.."&w=420&h=420"
	if duck.difficulty == "EASY" then
		duckFrame.DifficultyLabel.Text = duck.difficulty
		duckFrame.DifficultyLabel.BackgroundColor3 = Color3.fromRGB(25,191,0)
	elseif duck.difficulty == "MEDIUM" then
		duckFrame.DifficultyLabel.Text = duck.difficulty
		duckFrame.DifficultyLabel.BackgroundColor3 = Color3.fromRGB(255,170,0)
	elseif duck.difficulty == "HARD" then
		duckFrame.DifficultyLabel.Text = duck.difficulty
		duckFrame.DifficultyLabel.BackgroundColor3 = Color3.fromRGB(170,0,0)
	elseif duck.difficulty == "MYTHICHAL" then
		duckFrame.DifficultyLabel.Text = duck.difficulty
		duckFrame.DifficultyLabel.BackgroundColor3 = Color3.fromRGB(255,0,255)
	elseif duck.difficulty == "LIMITED" then
		duckFrame.DifficultyLabel.Text = duck.difficulty
		duckFrame.DifficultyLabel.BackgroundColor3 = Color3.fromRGB(255,255,255)
	elseif duck.difficulty == "EXCLUSIVE" then
		duckFrame.DifficultyLabel.Text = duck.difficulty
		duckFrame.DifficultyLabel.BackgroundColor3 = Color3.fromRGB(170, 85, 255)
	elseif duck.difficulty == "SOON" then
		duckFrame.DifficultyLabel.Text = duck.difficulty
		duckFrame.DifficultyLabel.BackgroundColor3 = Color3.fromRGB(0,0,0)
		duckFrame.DifficultyLabel.TextColor = BrickColor.new("White")
	end
	duckFrame.Namef.Text = duck.name
		if BadgeService:UserHasBadgeAsync(game.Players.LocalPlayer.UserId, duck.badgeID) then
			duckFrame.BackgroundColor3 = Color3.fromRGB(0, 255, 0) 
		else
			duckFrame.BackgroundColor3 = Color3.fromRGB(255, 0, 0) 
		end
end

This is the script in every duck:

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		game:GetService("BadgeService"):AwardBadge(player.UserId, 2129410072)
	end
end)

Also i have a Module script where all duck names, id, badgeId, ImageId, Id are, this is 1 duck:

	{
		ID = "NormalDuck",
		name = "Normal Duck",
		difficulty = "EASY",
		badgeID = 2129399897,
		imageID = 11552766665,
	},

Is it possible create one single script in ServerScriptService(Server Event) and put 1 script to all models like Firing the badge id or name to change the background of the ducks UI?

This is the image, the images in the frames are white because i didn’t put the images for now.

Thanks!

its been 2 hours, but i think that the reason it doesnt update is because you only run the loop once (first script)

Task.spawn(function) or RunService(), you can try to solve your loop and let it load infinitely.

You just ran the script just 1 time, whatever you did it ran like a normal local script would run, so create a RenderSteped or infinite loop that keeps identifying if it gets it already updated at the time.

local Ducks = require(game:GetService("ReplicatedStorage").DucksUIHandler.Ducks)
local BadgeService = game:GetService("BadgeService")

task.spawn(function()
	repeat task.wait(1/90)
		for _, duck in ipairs(Ducks) do
			--TODO:_Code
		end
	until false -- Until return false
end)

--TODO:___OR

game["Run Service"].RenderStepped:Connect(function()
	local T = 0
	if (tick() - T >= 1/90) then
		T = tick()
		
		for _, duck in ipairs(Ducks) do
			--TODO:_Code
		end
	end
end)

Hi, thanks for the response and the help, i tired the ode but it gives me in loop errors “UserHasBadgeAsync: failed to empty response”

Thanks

P.S.
Maybe it gives me error because i didnt put all the id’s?

By the way, if i edit the script and put your script all the gui broke(like there are double or triple of the same duck frame), and if i reset, in the output pops up an error saying TooManyRequests. How do i fix that and how do i refresh the gui for the new duck i find? Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.