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

What am I doing wrong?

These are basic chat commands. The first function set is for the admin, the person listed. Problem is, it seems that any player can activate the admin commands. I included the public commands in case it is interfering.

game.Players.PlayerAdded:connect(function(player) --Admin
    if player.Name == "shiningwindow" or "Player1" then
        player.Chatted:connect(function(msg)
			if (msg == "genesis") then
				queue.Value = "Home By The Sea"
			end
			if (msg == "???") then
				queue.Value = "???"
			else
				if game.ServerStorage:FindFirstChild(msg) then
					queue.Value = msg
				end
			end
        end)
    end
end)

local easteractive = false
game.Players.PlayerAdded:connect(function(player) --Easter Eggs
    player.Chatted:connect(function(msg2)
		if easteractive ~= true then --spam protection
			if (msg2 == "potato") then
				-- do stuff
			end
		end
    end)
end)

Any help is greatly appreciated!

2 comments

0

The names are case-sensitive, and change the "=" to "==". You do not need a "=" for this event. Also, you can combine the else and if to make "elseif"

0

This still doesn't answer why non-admin players can use the admin commands

2 answers

✓ Accepted answer
--In if statements, nil is considered false,
--and all that exists (besides the bool "false") is considered true.

if 1 then --A number is not nil. The following code will run.
	print("1 is considered true")
end

if "hey" then --A string is not nil. The following code will run.
	print("Strings considered true")
end

if workspace then --The workspace exists. The following code will run.
	print("The workspace is considered true")
end

if nil then --Nil is nil; it is the definition of non-existence. The following code will NOT run.
	print("Nil is considered true")
end

--Let's take a look at your code.

game.Players.PlayerAdded:connect(function(player)
    if player.Name == "shiningwindow" or "Player1" then --Here's the problem.
        player.Chatted:connect(function(msg)
            if (msg == "genesis") then
                queue.Value = "Home By The Sea"
            end
            if (msg == "???") then
                queue.Value = "???"
            else
                if game.ServerStorage:FindFirstChild(msg) then
                    queue.Value = msg
                end
            end
        end)
    end
end)

--"Player1" is a string, which is not nil/false, so the if statement must ALWAYS pass. Let's change that.

game.Players.PlayerAdded:connect(function(player)
    if player.Name == "shiningwindow" or player.Name == "Player1" then --Only pass if the name is shiningwindow or Player1.
        player.Chatted:connect(function(msg)
            if (msg == "genesis") then
                queue.Value = "Home By The Sea"
            end
            if (msg == "???") then
                queue.Value = "???"
            else
                if game.ServerStorage:FindFirstChild(msg) then
                    queue.Value = msg
                end
            end
        end)
    end
end)

2 comments

1

I totally missed that error! I feel dumb now, haha

1

Thank You!

Your first if statement should be after the player.Chatted event. It starts listening for every player after you've joined, rather than checking if the player who chatted was you. If you want it to only listen to you, that if statement has to be inside the Chatted event.

1 comment

0

Thank You!

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