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!
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
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