TestSound.TimeLength always returns 0

  1. What do you want to achieve? Keep it simple and clear!
    So what i want here is to make sound display the actual sound length

  2. What is the issue? Include screenshots / videos if possible!
    the TestSound instance always returning 0.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Tried doing Task.Delay, putting the instance creation in the function, any answers on dev hub didn’t work for me.

local function Validate(id)
	if not id or not tonumber(id) then return false end
	
	local success, result = pcall(function()
		return game:GetService("MarketplaceService"):GetProductInfo(id)
	end)
	
	if success and result and result.AssetTypeId == 3 then
		return true
		else
		return false
	end
end
		local Result = Validate(script.Parent.Text)
		if Result then
			local TestSound = Instance.new("Sound")
			TestSound.SoundId = "rbxassetid://"..tonumber(script.Parent.Text)
			TestSound.Volume = 0.001
			TestSound.Looped = false
			TestSound.RollOffMode = Enum.RollOffMode.Inverse
			TestSound:Play()
			task.wait(1)
			print(TestSound.TimeLength)
			if TestSound.TimeLength < 5 then
				print(TestSound)
				event:FireServer(script.Parent.Parent, script.Parent.Parent.Parent.Parent.Graphics.SoundID,Result,tonumber(script.Parent.Text))
				else
				print(TestSound)
				script.Parent.Text = ""
				script.Parent.Parent.Parent.Parent.Graphics.SoundID.TextBox.Text = ""
			end
				else
			script.Parent.Text = ""
			script.Parent.Parent.Parent.Parent.Graphics.SoundID.TextBox.Text = ""
		end
1 Like

Try this

if not sound.IsLoaded then
	sound.IsLoaded:Wait()
end

print(sound.TimeLength)

I tried that in a function before, it just doesn’t load i guess

Try not converting script.Parent.Text to a number in putting the sound id

and include the one @Nitefal posted before playing the sound

Still doesn’t load or print anything.

It seems never to load it. maybe it is because it is local script?

Have you tried to Parent TestSound somewhere

1 Like

yes that actually worked, thanks!

1 Like

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