Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Multiple Admin Commands?

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

✓ Accepted answer

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

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

1 comment

0

Nope, thats a minor error, It won't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.