Answered by
7 years ago Edited 7 years ago
You can't call LocalPlayer from a server script. If you wanted to achieve this, you could send a RemoteEvent to the player. The RemoteEvent would then allow the sound to be played in the local script.
It works in studio because there is only one local player (hence game.Players.LocalPlayer) being an instance.
The following script will work for your instance with a little revamp:
03 | local event = game.ReplicatedStorage.MusicEvent |
05 | script.Parent.Touched:connect( function (hit) |
06 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
08 | event:FireClient(player) |
14 | local event = game.ReplicatedStorage.MusicEvent |
19 | game.ReplicatedStorage.MusicEvent.OnClientEvent:connect( function (info) |
20 | if debounce then return end |
21 | local sound 50 = Instance.new( "Sound" , game.Players.LocalPlayer.PlayerGui) |