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

Multiple Admin Commands?

Asked by
PixelYT 30
9 years ago

I'm trying to make a holographic training center. I need to use Chat Commands to do it, my script works with one chat Command, but it cant do 2 in one script.

local GW = game.Workspace
local GWD = game.Workspace.Doors

local isAdmin = {["PixelYT"] = true, ["Vescatur"] = true, ["7035"] = true, ["Bladecrix"] = true, ["Player"] = true}

function onChatted(message, player)
    if message == "Open" and isAdmin[player.Name] then
        GWD.Door.Transparency = 1
        GWD.Door2.Transparency = 1
        GWD.Door.CanCollide = false
        GWD.Dooe2.CanCollide = false
    end
end

function onChatted(message, player)
    if message == "Close" and isAdmin[player.Name] then
        GWD.Door.Transparency = 0
        GWD.Door2.Transparency = 0
        GWD.Door.CanCollide = true
        GWD.Door2.CanCollide = true
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

That script opens a door, but only the Close command works, help please!

2 answers

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

Functions are kind of like variables in some aspects. They can be redefined.

Since scripts run down from line 1, the first function onChatted is replaced by the second one.

function onChatted(message, player)
    if message == "Open" and isAdmin[player.Name] then
        GWD.Door.Transparency = 1
        GWD.Door2.Transparency = 1
        GWD.Door.CanCollide = false
        GWD.Dooe2.CanCollide = false
    end
end

function onChatted(message, player)
    if message == "Close" and isAdmin[player.Name] then
        GWD.Door.Transparency = 0
        GWD.Door2.Transparency = 0
        GWD.Door.CanCollide = true
        GWD.Door2.CanCollide = true
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

You can fix this discrepancy by combining the two functions and "if" statements together.

function onChatted(message, player)
    if isAdmin[player.Name] then
        if message == "Open" then
            GWD.Door.Transparency = 1
            GWD.Door2.Transparency = 1
            GWD.Door.CanCollide = false
            GWD.Dooe2.CanCollide = false
        elseif message == "Close" then
            GWD.Door.Transparency = 0
            GWD.Door2.Transparency = 0
            GWD.Door.CanCollide = true
            GWD.Door2.CanCollide = true
        end
    end
end

NOTICE

Please take note that the commands for these executions are case sensitive. If you like it this way, then you can skip reading this. Otherwise, you can manipulate the string so your admins don't have to capitalize the first letter of the command.

function onChatted(message, player)
    message = message:lower()
    if isAdmin[player.Name] then
        if message == "open" then
            GWD.Door.Transparency = 1
            GWD.Door2.Transparency = 1
            GWD.Door.CanCollide = false
            GWD.Dooe2.CanCollide = false
        elseif message == "close" then
            GWD.Door.Transparency = 0
            GWD.Door2.Transparency = 0
            GWD.Door.CanCollide = true
            GWD.Door2.CanCollide = true
        end
    end
end
Ad
Log in to vote
0
Answered by
yumtaste 476 Moderation Voter
9 years ago

Line 11 - You put "Dooe2" instead of "Door2".

0
Nope, thats a minor error, It won't work. PixelYT 30 — 9y

Answer this question