This isn't working. Is there anything I am doing wrong? This script is suppose to find the player who touches the brick (the brick is a doorway and is invisible), and if the audio is playing, it would pause the audio, but if the player's audio is paused, it would play the audio rather.
function onTouch(hit) local a = game.Players.LocalPlayer.PlayerGui.Sound.IsPlayed local b = game.Players.LocalPlayer.PlayerGui.Sound.IsPaused if a ~= nil then game.Players.LocalPlayer.PlayerGui.Sound:Pause() else if b ~= nil then game.Players.LocalPlayer.PlayerGui.Sound:Play() end end end script.Parent.Touched:connect(onTouch)
function onTouch(hit) local a = game.Players:getPlayerFromCharacter(hit.Parent).PlayerGui.Sound.IsPlayed local b = game.Players:getPlayerFromCharacter(hit.Parent).PlayerGui.Sound.IsPaused if a then game.Players:getPlayerFromCharacter(hit.Parent).PlayerGui.Sound:Pause() elseif b then game.Players:getPlayerFromCharacter(hit.Parent).PlayerGui.Sound:Play() end end script.Parent.Touched:connect(onTouch)
Would this work?
function onTouch(hit) local a = game.Players:getPlayerFromCharacter(hit.Parent).PlayerGui.Sound.IsPlayed local b = game.Players:getPlayerFromCharacter(hit.Parent).PlayerGui.Sound.IsPaused if a then game.Players:getPlayerFromCharacter(hit.Parent).PlayerGui.Sound:Pause() elseif b then game.Players:getPlayerFromCharacter(hit.Parent).PlayerGui.Sound:Play() end end script.Parent.Touched:connect(onTouch)
Those properties would always be true or false, never nil. So your condition will always be true. Try this:
function onTouch(hit) local a = game.Players.LocalPlayer.PlayerGui.Sound.IsPlayed local b = game.Players.LocalPlayer.PlayerGui.Sound.IsPaused if a then game.Players.LocalPlayer.PlayerGui.Sound:Pause() elseif b then game.Players.LocalPlayer.PlayerGui.Sound:Play() end end script.Parent.Touched:connect(onTouch)