Sound Time Position Help

image
the sound plays when you equip the tool.

script.Parent.Equipped:Connect(function()
	script.Parent.ugh:Play()
end)

script.Parent.Unequipped:Connect(function()
	script.Parent.ugh:Stop()
end)

You still need to do this. Currently you’re only updating it once, but you need it to update every time the time position changes.

im kinda stuck here

function changeLabel()
	label.Text = string.format("%d:%2d", math.floor(tool.ugh.TimePosition / 60), tool.ugh.TimePosition%60)
end

character.ChildAdded:Connect(function(tool: Tool)
	if tool:IsA("Tool") then
		sound:GetPropertyChangedSignal("TimePosition"):Connect(changeLabel)
	end
end)

how do i still detect the tools sound without it calling an index error
in the function not the bottom code.

local connection

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

	if tool:IsA("Tool") then
        if connection then
            connecton:Disconnect()
        end
		connection = sound:GetPropertyChangedSignal("TimePosition"):Connect(changeLabel)
	end
end)

still stays the same way. Is there anything i can do to make it more simple?

once again no error

surprisingly this worked for me.


function changeLabel()
	game.Players.LocalPlayer.PlayerGui.FnfGui.MainBar.Label.Text = string.format("%d:%2d", math.floor(script.Parent.ugh.TimePosition /60), script.Parent.ugh.TimePosition%60)
end
for i,x in pairs(script.Parent:GetDescendants()) do
	if x:IsA("Sound") then
		script.Parent.ugh:GetPropertyChangedSignal("TimePosition"):Connect(changeLabel)
	end
end

thanks for helping

1 Like