I am attempting to make UI have certain functions built into each UI element such as updating stats. The game I am making uses custom characters so I disabled character auto loads… When I disable character autoloads it causes my script to give the error "infinite yield possible on “SidebarUI.Main” Even though when I check in game my player gui has the correct UI’s loaded in. Here is my code
local Sidebar = {}
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local PlayerGui = Player:WaitForChild("PlayerGui")
local SidebarUI = PlayerGui:WaitForChild("SidebarUI")
local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")
--//FUNCTIONS
function Sidebar:updateCoins(newValue)
SidebarUI.Main.Coins.CoinText.Text = newValue
end
function Sidebar:updateGems(newValue)
SidebarUI.Main.Gems.GemText.Text = newValue
end
function Sidebar:updateEggs(newValue1, newValue2)
SidebarUI.Main.Eggs.EggText.Text = newValue1.."/"..newValue2
end
function Sidebar:Tween(state, waitUntilFinished)
local TweenPosition
if state then
TweenPosition = UDim2.new(0,0,0,0)
else
TweenPosition = UDim2.new(-1,0,0,0)
end
local tween = TweenService:Create(SidebarUI.Main, TweenInfo.new(1.5), {Position = TweenPosition})
tween:Play()
if waitUntilFinished then
tween.Completed:Wait()
end
return true
end
--//BUTTONS
SidebarUI:WaitForChild("Main").SellButton.MouseButton1Click:Connect(function()
SoundService.UI.OpenSoundEffect:Play()
Character.HumanoidRootPart.CFrame = CFrame.new(-5.899, 8.277, -33.903)
end)
return Sidebar
Here is a photo of my current UI setup in a live game where I got the error