script.Parent.Touched:Connect(function(hit) if script.Parent.Playing.Value == true then return else if(hit.Parent:FindFirstChild("Humanoid")~=nil)then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local sound = player.PlayerGui.OutdoorSound if script.Parent.Parent.Stairwell.Playing.Value == true then player.PlayerGui.StairwellSound:Stop() script.Parent.Parent.Stairwell.Playing.Value = false sound:Play() else script.Parent.Playing.Value = true sound:Play() end end end end)
This is because you tried to access the PlayerGui
from the server. Place the sound in the part, and play it there.
You are accessing the player from the server. I'm guessing that this is on FE. In the line
local sound = player.PlayerGui.OutdoorSound
you are trying to access the PlayerGui, but it has nothing from the server's point of view. In Studio, it does not have that, so it works fine in Studio. A fix for this would to have a remote event or something to tell the client that it should play the sound.
If you're using a Script with experimental mode off, the server can't view the descendants of each clients' PlayerGui. This does work in studio because everything in studio is ran on the client.
You could make a sound play locally by re-writting the script in a client-sided(local) script, or using a RemoteEvent, the listener which will be the LocalScript, will play the sound, while your server-sided(normal) script will fire the event to play the sound for the client.