Sound Time Position Help

Hello All, so today i was looking through old scripts and i saw a time position script. It looked pretty messy so i TRIED to remake it but i ended up with this

local playersStarterPark = game.Players.LocalPlayer.Character
local characterTool = playersStarterPark:FindFirstChildWhichIsA("Tool")

local sound = characterTool.ugh
local label = script.Parent.TIme

characterTool.Equipped:Connect(function()
	label.Text = string.format("%d:%02d", math.floor(sound.TimePosition/60), sound.TimePosition%60)
end)

doesn’t even work lol. I seriously need help on this

1 Like

im really sleepy so my brain is so dead rn

1 Like

Could we please have more context into what the hell your doing.
As of right now, we don’t even know what your problem is, nonetheless what the table sound is supposed to represent / hold

2 Likes

You need to react to changes in the sound’s time position.

function changeLabel()
    -- update the label text here
end

sound:GetPropertyChangedSignal("TimePosition"):Connect(changeLabel)
1 Like

like i said, i don’t know im being insanely dumb right now. im trying to make when a text label replicates how long the song has been going for. i apologize for you not understanding, hope this clears it

1 Like

im pretty sure its gonna make the numbers like

0.989909809890

and not

0

Is that not why you’ve chosen %d?

Put this inside the function body.

1 Like

And what is currently wrong with it. Is your rounding not working properly, is it a replication problem…?

just doesn’t function at all. ill see what i can do with the our guys help, brb

1 Like

well, at least it functions. it just won’t replicate the song time position
image

buster. I’ll see what i can do from here now, ill mark it as a solution since it gave me an easier way to fix. Thanks!

2 Likes
local playersStarterPark = game.Players.LocalPlayer.Character
local characterTool = playersStarterPark:FindFirstChildWhichIsA("Tool")

local sound = characterTool.ugh
local label = script.Parent.TIme -- Is that what it's named?

while task.wait(1) do -- Ik, bad practice, sue me.
    label.Text = string.format("%d:%2d", math.floor(sound.TimePosition / 60), sound.TimePosition%60)
end

In theory, this should work! :smile:

You could also do this:

local runService = game:GetService("RunService")

local playersStarterPark = game.Players.LocalPlayer.Character
local characterTool = playersStarterPark:FindFirstChildWhichIsA("Tool")

local sound = characterTool.ugh
local label = script.Parent.TIme -- Is that what it's named?

runService.Heartbeat:Connect(function()
    label.Text = string.format("%d:%2d", math.floor(sound.TimePosition / 60), sound.TimePosition%60)
end)

(I have no freaking idea if Heartbeat is the right one, otherwise, it’s RenderStepped. But I think it is Heartbeat!)

seems like theres an error
image

If it says “attempt to index nil”, it means that the thing you indexed (characterTool) is nil.

Try using WaitForChild.

weird. want me to show you a video of what i want so it can be simpler to fix?

Oh, I see.

You also need to wait for the character.

local character = player.Character or player.CharacterAdded:Wait()
local tool = character:WaitForChild("Tool") -- or whatever you've named it

Btw, on the

local tool 

part, im trying to detect when the character has a tool not the tool name

Example:
image
im trying to detect when they have a tool equipped*

In that case, you can use an event:

character.ChildAdded:Connect(function(tool: Tool)
    if tool:IsA("Tool") then
        -- do stuff
    end
end)

does this


no error either?

source code


local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local label = script.Parent.Label

character.ChildAdded:Connect(function(tool: Tool)
	if tool:IsA("Tool") then
		label.Text = string.format("%d:%2d", math.floor(tool.ugh.TimePosition / 60), tool.ugh.TimePosition%60)
	end
end)

Can you open the Explorer and check that the sound time is replicating to the client?

This is the only thing I can think of, since everything else looks okay…