Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Audio Script? Anything wrong with it? [Unsolved]

Asked by
RAYAN1565 691 Moderation Voter
10 years ago

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)

3 answers

Log in to vote
1
Answered by 6 years ago
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)
Ad
Log in to vote
1
Answered by
RAYAN1565 691 Moderation Voter
10 years ago

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)
Log in to vote
0
Answered by
jakedies 315 Trusted Moderation Voter Administrator Community Moderator
10 years ago

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)
0
Still didn't work :p RAYAN1565 691 — 10y
0
You are using localplayer, you have to get the player using GetPlayerFromCharacter method. jakedies 315 — 10y
0
Check my answer. RAYAN1565 691 — 10y
0
Yeah but you could be more efficient just by calling the GetPlayerFromCharacter function once instead of 4 times. jakedies 315 — 10y
View all comments (2 more)
0
Thats not a function.. Thats a method Operation_Meme 890 — 10y
0
Methods are functions. So it is a function since all methods are functions. jakedies 315 — 10y

Answer this question