If statement not working properly

I am adding an easter egg to my game so that when you say “let me be clear” it will make you clear, but the problem is whenever you chat it makes you transparent, and I don’t know why

local ts = game:GetService("TweenService")

game.ReplicatedStorage.SpecialChatEvent.OnServerEvent:Connect(function(plr,text)
	if text == "Let me be clear" or "let me be clear" then
		local char = plr.Character
		local things = char:GetDescendants()
		for i = 1, #things do
			if things[i]:IsA("BasePart") or things[i]:IsA("Decal") and things[i].Name ~= "HumanoidRootPart" then
				local Info = TweenInfo.new(3)
				local Tween = game:GetService("TweenService"):Create(things[i],Info,{Transparency=0.85})
				Tween:Play()
			end
		end
	end
end)
1 Like

Can we see the script where you’re firing over the information (and detecting when they chat?)

Oh and you cant check if text is equal to both of these at once, you’d have to compare text to each individual one like this:

if text == "Let me be clear" or text == "let me be clear" then

Or you could just use string.lower which turns everything in a string lowercase

if string.lower(text) == "let me be clear" then
2 Likes
local tts = game:GetService("TextChatService")

tts.OnIncomingMessage = function(msg)
	game.ReplicatedStorage.SpecialChatEvent:FireServer(msg.Text)
end
2 Likes

Okay maybe try adding a print statement after the ig statement and see if it makes it past that line?

The line I’m referring to:

it does

filler text filler text

1 Like

@Doomcolp has stated the correct solution so I suggest following their post. In addition to this I also suggest changing it to player.Chatted instead of receiving it from the client because:

    1. It is the same thing since you are looking for every message coming from textchatservice
    1. Client side can be exploited by exploiters and false information can be sent to the server, for example the “let me be clear” prompt can be sent by exploiters even though they haven’t said it
    1. player.Chatted returns an unfiltered version of the message, this allows you to check for the message without worrying about filters.
3 Likes

You need to write it like

--Code A
if text == "Let me be clear" or text == "let me be clear" then 

or write it if string.lower(text) == "let me be clear" then @Doomcolp said same thing.
even text isn’t “Let me be clear”, it passes because “Let me be clear” is literally “Let me be clear”.
It’s like SQL injection. hackers uses it to access server even password or username is wrong

example:

if password or 1 == 1 

also you can do it like this

-- Code B
local Texts = {
    "Let me be clear",
    "let me be clear"
}

if table.find(Texts,text) then

but it will be long so Code A is better. use Code B for long If statement.

and

		local things = char:GetDescendants()
		for i = 1, #things do
			if things[i]:IsA("BasePart") or things[i]:IsA("Decal") and things[i].Name ~= "HumanoidRootPart" then
				local Info = TweenInfo.new(3)
				local Tween = game:GetService("TweenService"):Create(things[i],Info,{Transparency=0.85})
				Tween:Play()
			end
		end

You can make it like this:

for i,thing in ipairs(char:GetDescendants()) do
   if thing:IsA("BasePart") or thing:IsA("Decal") and thing.Name ~= "HumanoidRootPart" then
				local Info = TweenInfo.new(3)
				local Tween = game:GetService("TweenService"):Create(thing,Info,{Transparency=0.85})
				Tween:Play()
   end
end

this for statement is for processing table

1 Like

I’m really sorry but I forgot to reply lol

But a print statement in the in pairs loop outside of the if statement’s scope and also one in the if statement’s scope

Just to see if the code is running. & if it is, then I’ll try to do some testing on my own

Also both wiizzzzzzzaaaaard and ALonelyGalaxy are right too (dont feel like typing a lot today though but yeah)


just figured it out lol after the solution was marked

you can’t index a child from an Instance with a number in square braces like that. You’d need to use Parent:GetChildren() and use square brace notation there.

But using a in pairs loop like wiizzzzzzzaaaaard did is the better solution

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.