Issue with local script

I’ll make it simple.

When player joins the GUI appear and say “Now playing: [SONGNAME]” then disappear after a while

The GUI will appear again when the song is over with a wait(Song.TimeLenght+10)

The issue: If a player joins when the song is already started the GUI will appear after the difference time between song lenght and join time (If the player joined when the music was at 1 minute the GUI will appear when the next song is at 1 minute and not at the start of it)
Same if the player resets character or dies in any way.

Is there a way to make the GUI only appear when the song starts?
Even if the player joins after 2 minutes the GUI will appear one time then wait till the next start

Script:

SongModule = require(workspace.Songs.ModuleScript)
TweenService = game:GetService("TweenService")
local frame = script.Parent


wait(10)

while true do
	r = workspace.SongScript.Value.Value
	script.Parent.Text = ("Now Playing: ".. SongModule[r].Name)
	
	frame.AnchorPoint = Vector2.new(0.5, 0.5)
	frame.Position = UDim2.new(3, 0, 0.5, 0)

	-- Set up tweens
	local tweenInfo1 = TweenInfo.new(20, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local tween1 = TweenService:Create(frame, tweenInfo1, {Position=UDim2.new(-3, 0, 0.5, 0)})

	tween1.Completed:Connect(function()
		repeat
			script.Parent.Parent.BackgroundTransparency = script.Parent.Parent.BackgroundTransparency+0.03
			wait()
		until script.Parent.Parent.BackgroundTransparency >= 1
	end)

	tween1:Play()
	
	wait(workspace.Songs.Playing.TimeLength+10)
	repeat
		script.Parent.Parent.BackgroundTransparency = script.Parent.Parent.BackgroundTransparency-0.05
		wait()
	until script.Parent.Parent.BackgroundTransparency <= 0
end

There is not substantial material for us to review. Could you provide the script? I believe there were some logical errors when it comes to this.

1 Like

Sure, Added the script to the topic
The script is in StarterGUI > Frame > TextLabel > “LocalScript”

I believe you’re going to need an alternate method to avoid inaccuracies in the wait time. The issue is it does not account to the duration left, but the entire length of it.

i also tried to change it from LocalScript to Script but i think that the Starter GUI just resets when a player join or dies.

I have to try changing the GUI from workspace or scriptstorage and with events or other things start the tween

I don’t think you want to use a normal script for handling the GUIs, normally you want LocalScripts to manage them. Revert it back and set the duration as TimeLength - TimePosition + 10.

https://developer.roblox.com/api-reference/property/Sound/TimeLength
https://developer.roblox.com/api-reference/property/Sound/TimePosition

1 Like

This actually worked, I didn’t think about it.
Thank you!