Music Gui works in studio but not in uploaded game

Hello, DevForum users. I do know there is a similar topic as this, but this is a different gui as his, this is the reason why I’m seeking help from here.

My current issue is, my music gui which is suppose to show what music is playing in the game, and the title of this music. But the issue is, when I publish the game to Roblox, tested in the main game. It doesn’t show the title, when it works in Studio.

I tried looking for solutions in Youtube and DevForum, still didn’t get what they are saying or couldn’t find what I wanted to fix.

Here’s some image, hope some of you guys could find the solution to this annoying matter of mine.

This is the script in the replicatedfirst.

local plr = game.Players.LocalPlayer
local ui = plr:WaitForChild("PlayerGui"):WaitForChild("Music Bar", 99):WaitForChild("MUSICBAR",99)
local sound = game.Workspace:WaitForChild("SongAudio")
local Events = {}
for i,v in pairs(game.ReplicatedStorage.Events:GetChildren()) do Events[v.Name] = v end
local event = Events["PlayingRemote"]
local runService = game:GetService("RunService")
local ts = tostring
local mf = math.floor

if event then
	print 'loaded'
else
	return
end

local function getTime(mode, t)
	if mode == "max" then
		local sec = 0
		local min = 0
		local length = mf(t)
		for i = 1, length do
			sec = sec + 1
			if sec >= 60 then
				min = min + 1
				sec = 0
			else
				sec = length - 60 * min
			end
			runService.RenderStepped:wait()
		end
		if ts(sec):len() < 2 then
			sec = "0" .. ts(sec)
		end
		wait()
		return min .. ":" .. sec
	elseif mode == "cur" then
		do
			local sec = 0
			local min = 0
			local position = mf(t)
			sec = position
			function checksec()
				wait()
				if sec >= 60 then
					min = min + 1
					sec = sec - 60
					checksec()
				end
			end
			checksec()
			sec = ts(sec)
			if ts(sec):len() < 2 then
				sec = "0" .. ts(sec)
			end
			return min .. ":" .. sec
		end
	end
end

event.OnClientEvent:Connect(function(songName, songArtist, boolRequested, requestedUser)
	repeat wait()
	until sound.isLoaded == true
	wait()
	ui.song.Text = songName
	ui.artist.Text = songArtist
end)

Are there any errors? From briefly looking at it, it seems like the issue is with how you automatically load your events. Since it’s running on the client the events might not exist by the time that loop runs.

1 Like

From what I see in the developer console, there are no errors.

There are no errors because you return if there is no event, which prevents the rest of the code from running. Using WaitForChild should fix it.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local eventsFolder = ReplicatedStorage:WaitForChild("Events")
local event = eventsFolder:WaitForChild("PlayingRemote")
1 Like

Like this?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local eventsFolder = ReplicatedStorage:WaitForChild("Events")
local event = eventsFolder:WaitForChild("PlayingRemote")
local plr = game.Players.LocalPlayer
local ui = plr:WaitForChild("PlayerGui"):WaitForChild("Music Bar", 99):WaitForChild("MUSICBAR",99)
local sound = game.Workspace:WaitForChild("SongAudio")
local Events = {}
for i,v in pairs(game.ReplicatedStorage.Events:GetChildren()) do Events[v.Name] = v end
local event = Events["PlayingRemote"]
local runService = game:GetService("RunService")
local ts = tostring
local mf = math.floor

That should work, just remove the following lines:

local Events = {}
for i,v in pairs(game.ReplicatedStorage.Events:GetChildren()) do Events[v.Name] = v end
local event = Events["PlayingRemote"]
1 Like

It works, thanks alot! Took sometime for the song to load.