Unable to cast string to int64

I am getting the error image
this is my code

local MarketPlaceService = game:GetService("MarketplaceService")

local SongLabel = script.Parent.SongLabel
local SkipButton = script.Parent.SkipButton
local MuteButton = script.Parent.MuteButton

wait(1)
while true do
    local Sounds = script:GetChildren()
    local RandomIndex = math.random(1,#Sounds)
	local RandomSound = Sounds[RandomIndex]
	local id = RandomSound.SoundId
	local SongInfo = MarketPlaceService:GetProductInfo(id)
	SongLabel.Text = SongInfo.Name
    RandomSound:Play()
    wait(RandomSound.TimeLength)
end

Is this the full script? There isn’t 22 lines of code here.

oop the other stuff is comments tho but ill send the full thing

local MarketPlaceService = game:GetService("MarketplaceService")

--local Songs = {
--	7029024726, 
--	7023617400, 
--	7023598688, 
--	5410086218, 
--	1838660362,
--	1847606521
--}

local SongLabel = game.StarterGui.MusicGUI.Frame.SongLabel
--local SkipButton = script.Parent.SkipButton
--local MuteButton = script.Parent.MuteButton

wait(1)
while true do
    local Sounds = script:GetChildren()
    local RandomIndex = math.random(1,#Sounds)
	local RandomSound = Sounds[RandomIndex]
	local id = RandomSound.SoundId
	local SongInfo = MarketPlaceService:GetProductInfo(id)
	SongLabel.Text = SongInfo.Name
    RandomSound:Play()
    wait(RandomSound.TimeLength)
end

What are Sounds? (local Sounds = script:GetChildren())

just songs image
the error is on this line image

A Sound’s SoundId property is a string, hence why it includes “rbxassetid://…” or “https://roblox.com/…”, but GetProductInfo requires a number. You would have to get the number from the string using string patterns and then convert it to a number:

local SongInfo = MarketPlaceService:GetProductInfo(tonumber(id:match("%d+")))

Okay.


I assume you’re trying to make a music player system that picks a random song and plays it? You’ve chosen quite an odd method to do this, you don’t need each sound instance if you have each songID already in a table, simply have 1 sound instance and edit that one.

local MarketPlaceService = game:GetService("MarketplaceService")

-- Don't comment this, the script will ignore it

local Songs = {
	7029024726, 
	7023617400, 
	7023598688, 
	5410086218, 
	1838660362,
	1847606521
}

local SongLabel = game.StarterGui.MusicGUI.Frame.SongLabel
--local SkipButton = script.Parent.SkipButton
--local MuteButton = script.Parent.MuteButton

local SoundObject = workspace.Sound -- [Create this]

wait(1)
while true do
    -- local Sounds = script:GetChildren() [We don't need this anymore]
    local RandomID = Songs[math.random(#Sounds)] -- Get a random song ID
	local SongInfo = MarketPlaceService:GetProductInfo(RandomID)
	SongLabel.Text = SongInfo.Name
 
    SoundObject.SoundId = RandomID    
    SoundObject:Play()

    task.wait(SoundObject.TimeLength) -- Since wait is deprecated, we'll use task.wait(
end

Ignore that, it should work fine.

If the error bothers you, just replace it with Songs[math.random(1, #Sounds)]

1 Like

Bro roblox studio has gotten so laggy on really good hardware even image
also that error is causing problems image

Oh my bad, I made a typo.
Replace Songs[math.random(1, #Sounds)] with Songs[math.random(1, #Songs)]

1 Like

this did work but didnt update the label

still image oop my bad didnt put a s

oh my

That means your sound IDs are invalid

This should fix your initial issue.

local MarketPlaceService = game:GetService("MarketplaceService")

local SongLabel = script.Parent.SongLabel
local SkipButton = script.Parent.SkipButton
local MuteButton = script.Parent.MuteButton

wait(1)
while true do
    local Sounds = script:GetChildren()
    local RandomIndex = math.random(1,#Sounds)
	local RandomSound = Sounds[RandomIndex]
	local id = string.match(RandomSound.SoundId, "%d+")
	local SongInfo = MarketPlaceService:GetProductInfo(id)
	SongLabel.Text = SongInfo.Name
    RandomSound:Play()
    wait(RandomSound.TimeLength)
end
1 Like

no they are not limittttttttttt

TYSM that fixed it limitttttttt

No problem, though this guy has said it before me.

Please refer to the wiki in case you input the incorrect value types.

1 Like