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

What am I doing wrong?

Asked by 8 years ago

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!

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" Decemus 141 — 8y
0
This still doesn't answer why non-admin players can use the admin commands ShiningWindow 127 — 8y

2 answers

Log in to vote
1
Answered by
funyun 958 Moderation Voter
8 years ago
--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)
1
I totally missed that error! I feel dumb now, haha Lamar 45 — 8y
1
Thank You! ShiningWindow 127 — 8y
Ad
Log in to vote
2
Answered by
Lamar 45
8 years ago

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.

0
Thank You! ShiningWindow 127 — 8y

Answer this question