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

mainmenu/on works but not mainmenu/off, can someone help?

Asked by 10 years ago

So I have a script where if you say mainmenu/on, or off, it will make the mainmenu pop up. Well for some reason when I tested it I said "mainmenu/on", it worked, but when I tried mainmenu/off, it did not go away. Can someone fix this? Here's the script, if you could please?

local function onChatted(msg, recipient, speaker)

local msg = msg:lower()

if msg == "mainmenu/on" then

if not speaker.PlayerGui["ScreenGui"].Frame.Visible == true then

speaker.PlayerGui["ScreenGui"].Frame.Visible = true

elseif msg == "mainmenu/off" then

if not speaker.PlayerGui["ScreenGui"].Frame.Visible == false then

speaker.PlayerGui["ScreenGui"].Frame.Visible = false

end

end

end

end



function onPlayerEntered(newPlayer)



newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)

end





game.Players.PlayerAdded:connect(onPlayerEntered)


2 answers

Log in to vote
0
Answered by
Asleum 135
10 years ago

It's just a problem of misplaced end's. Try this :

local function onChatted(msg, recipient, speaker)

local msg = msg:lower()

if msg == "mainmenu/on" then

if not speaker.PlayerGui["ScreenGui"].Frame.Visible == true then

speaker.PlayerGui["ScreenGui"].Frame.Visible = true

end

elseif msg == "mainmenu/off" then

if not speaker.PlayerGui["ScreenGui"].Frame.Visible == false then

speaker.PlayerGui["ScreenGui"].Frame.Visible = false

end

end

end



function onPlayerEntered(newPlayer)



newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)

end





game.Players.PlayerAdded:connect(onPlayerEntered)



Ad
Log in to vote
0
Answered by 10 years ago

Try, if that works.

local function onChatted(msg, recipient, speaker)
    local msg = msg:lower()
    if msg == "mainmenu/on" then
        speaker.PlayerGui["ScreenGui"].Frame.Visible = true
    end
    if msg == "mainmenu/off" then
        speaker.PlayerGui["ScreenGui"].Frame.Visible = false
    end
end

function onPlayerEntered(newPlayer)
    newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

Answer this question