So have this placed under the workspace in a normal script
function onPlayerAdded(player)
player.CharacterAdded:connect(function(character)
script.Dinamic:clone().Parent = character
end)
end
game.Players.PlayerAdded:connect(onPlayerAdded)
Dinamic is a localscript that has the following inside:
local character = script.Parent
local player = game.Players.LocalPlayer
if script.Value.Value == 1 then
player.PlayerGui.Flute:Play()
elseif script.Value.Value == 2 then
player.PlayerGui.Piano:Play()
end
local playing = false --false = flute true = piano
script.Parent.Head.Touched:connect(function(hit)
if hit.Name == "Music" and playing == false then
player.PlayerGui.Flute:Stop ()
player.PlayerGui.Piano:Play ()
playing = true
wait()
elseif hit.Name == "Music" and playing == true then
player.PlayerGui.Piano:Stop ()
player.PlayerGui.Flute:Play ()
playing = false
wait()
end
end)
Value is a numValue placed inside the localscript and its default value is 1. This script works correctly in solo mode but in online mode it does not work and I have no idea why, maybe the PlayerAdded Event doesn't fire correctly ?

2 comments
Try giving this a read. https://scriptinghelpers.org/blog/it-works-in-studio-but-not-online
I already read it but I can't figure out what's wrong with it, I did a few changes to the script before posting here based on what I read from there. I'm pretty new to this so some things that may seems obvious are not to me.