Basically when i step on a part a sound will play inside the players PlayerGui and this works PERFECTLY in studio but when i go to the actual game when i step on the part it does not instance the sound in the PlayerGui help??
cooldown = 50--Put amount of seconds for cooldown to last. db = false script.Parent.Touched:connect(function(hit) if db == false then db = true local sound50 = Instance.new("Sound", game.Players.LocalPlayer.PlayerGui) sound50.Playing = "true" sound50.SoundId = "rbxassetid://184219038" wait(40) sound50:Remove() wait(cooldown) db = false end end)
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:
-- SERVER SCRIPT (PUT THIS IN YOUR PART) local event = game.ReplicatedStorage.MusicEvent -- This is the remote event. script.Parent.Touched:connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player ~= nil then event:FireClient(player) end end) -- LOCAL SCRIPT (PUT THIS IN STARTERGUI) local event = game.ReplicatedStorage.MusicEvent -- The remote event. local debounce = false local cooldown = 50 game.ReplicatedStorage.MusicEvent.OnClientEvent:connect(function(info) if debounce then return end -- If the debounce is true then stop the script local sound50 = Instance.new("Sound", game.Players.LocalPlayer.PlayerGui) sound50.SoundId = "rbxassetid://184219038" sound50:Play() -- More efficient way to play. wait(40) sound50:Destroy() -- More updated version of removing an object wait(cooldown) debounce = false end)