Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Club Gui Wont Change Gui Text When Music Is Changed Any Help?

Local Script:

--/ Variables
local MusicTopBar = script.Parent.MusicTopBar
local Progress = MusicTopBar.Progress
local Bar = Progress.Bar
local SongName = MusicTopBar.SongName
local SongUploader = MusicTopBar.SongUploader

local SongNameText = "Song: "
local SongUploaderText = "Uploaded By: "

local MarketplaceService = game:GetService("MarketplaceService")

local SoundService = game:GetService("SoundService")
local Music = SoundService:WaitForChild("Music")

local MusicInfo = {
	MusicName = "",
	MusicUploader = "",
}

--/ Functions
function SetGuiText(N,U)
	SongName.Text = SongNameText..N
	SongUploader.Text = SongUploaderText..U
end

function getId()
	if string.sub(Music.SoundId,1,31) == "http://www.roblox.com/asset/?id=" then
		return string.sub(Music.SoundId,31,string.len(Music.SoundId))
	elseif string.sub(Music.SoundId,1,13) == "rbxassetid://" then
		return string.sub(Music.SoundId,13,string.len(Music.SoundId))
	elseif tonumber(Music.SoundId) then
		return Music.SoundId
	end
end

Music.Changed:Connect(function()
	if Music.Playing ~= false then
		local Id = getId()
		local Info = MarketplaceService:GetProductInfo(Id)
		SetGuiText(Info.Name,Info.Creator.Name)
	end
	if Music.TimePosition > 0 then
		Bar:TweenSize(UDim2.new(Music.TimePosition/Music.TimeLength,0,0,4),"Linear","Out",true,0.5)
	end
end)

Error: 17:09:27.095 - Unable to cast string to int64 17:09:27.097 - Stack Begin 17:09:27.098 - Script 'Players.Professional_Lua.PlayerGui.Main.Main', Line 40 17:09:27.098 - Stack End

1 answer

The function getId() is returning the id as string. The parameters for GetProductInfo requires int64 (numbers), so you'll have to convert the string using tonumber(string).

Music.Changed:Connect(function()
    if Music.Playing ~= false then
        local Id = getId()
        local Info = MarketplaceService:GetProductInfo(tonumber(id))
        SetGuiText(Info.Name,Info.Creator.Name)
    end
    if Music.TimePosition > 0 then
        Bar:TweenSize(UDim2.new(Music.TimePosition/Music.TimeLength,0,0,4),"Linear","Out",true,0.5)
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.