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

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

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)

4 comments

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")

0

Alright thanks. It worked :)

1

Add [SOLVED] or something to your question so people don't get misdirected.

0

Crap, he hid his private code. How are we going to steal his trade secrets now?

1 answer

✓ Accepted answer

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.

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