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

[Solved] Why is this Chatted script activating on everything?

Asked by 9 years ago

This activated even if I were to say for example "g"

function Chatted(msg)
    if msg:sub(1,3) == "God" and player.Name == "Polendris" or player.Name == "Player" then
        --private code here
    end
end

player.Chatted:connect(Chatted)
1
The problem is that you have an or operator in your if statement. If player's name is "Player", it will run no matter what. Add a parenthesis, like this: if msg:sub(1,3) == "God" and (player.Name == "Polendris" or player.Name == "Player") LetThereBeCode 360 — 9y
0
Alright thanks. It worked :) ZeroCrimson 35 — 9y
1
Add [SOLVED] or something to your question so people don't get misdirected. LetThereBeCode 360 — 9y
0
Crap, he hid his private code. How are we going to steal his trade secrets now? Legojoker 345 — 9y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

The if statement is a and b or c and because of the boolean order of operations, this is interpreted as (a and b) or c and since c is true, the statement is true regardless of a and b. Use parentheses to solve this.

Ad

Answer this question