Music System broken

So I have a music system that works perfectly well, but when I refresh or reset my character, the song title disappears. The script will be below if you decide to help.

Before reseting

After reseting

Here’s the script for the song titles:

local Player = game.Players.LocalPlayer


local event = game:GetService("ReplicatedStorage"):WaitForChild("MusicUpdate")

event.OnClientEvent:connect(function(info)
	if info then
		script.Parent.Text = "Currently playing: " .. info.Name
	end
end)

Please help ;(

1 Like

You’re only firing the event once on a musicupdate song, instead you should have a server value on eg Workspace that’s a string value for the song name which on value update you will set the song name and also from grabbing the value. This way it will keep on reset.

If I am correct the server is firing the client with the data, as the local script is connected to the character then it will remove that local script.

I would consider parenting the local script to the player instead. This way it will remain running until the player leaves.


Failing that you can add in death detection so when the character dies it will fire the server asking it to send the music data to the client.

How do i parent the local script with the player?

Use ‘starter Player scripts’ as the parent

uhm. is this right?

Make sure the textlable name matches, and it should be case sensitive. but other than that it seems correct.

Personally when checking if something exists I go for
if data == nil then
Somethings wrong
else
It has something
end

Though I doubt it will make much difference I just find it handles much better, Plus its good practice to have some kind of error handling / reporting.

Edit:
On second thought, I just noticed your trying to get the gui from the startergui. When a player loads in the gui you want to change wont be there. It will be in the players gui instead. Im not on studio right now so I cant tell you the exact way to do it but if you hit play and go into your players descendants you will be able to find it.

You could make a string value that’ll have the sound’s name and keep your text updated by daily basis using function, such as:

local val = game.ReplicatedStorage:FindFirstChild("Your_String_Value").Value
local text = script.Parent.Text

local function updateText()
    if not string.match(text, val) then
        text = val
    end
end

game:GetService("RunService").RenderStepped:Connect(function()
    updateText()
end)

-- or you can do while true do function, basically anything that'll keep you on track

-- if you dont want to check repetitively, you could use Humanoid.Died and itll update the text upon respawn
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("Humanoid").Died:Connect(function()
    if not string.match(text, val) then
        text = val
    end
end)

I’m not quite sure why you’re being told to all of this elaborate stuff, when you could simply disable the Gui.ResetOnSpawn property. Am I missing something here? Anyway, it keeps the GUI from resetting when the player resets or dies. This should fix your problem.

2 Likes

Oh, I forgot that this even existed since I used it a long time ago, but that should work perfectly fine.

1 Like