My game is a Dragon Ball Quiz and the first door is supposed to open when you say "dragon ball" but I also want it to open if you say "dragonball" and when I tried to edit it for more than one phrase, the line for it went red. Here's the entire script: door = script.Parent --this is the door
function onChatted(msg, recipient, speaker) -- convert to all lower case local source = string.lower(speaker.Name) msg = string.lower(msg) if (msg == "dragon ball", "dragonball") then --This line turned red when I added , "dragonball" door.CanCollide = false door.Transparency = 0.7 wait(5) door.CanCollide = true door.Transparency = 0 end end function onPlayerEntered(newPlayer) newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) end game.Players.ChildAdded:connect(onPlayerEntered)
Any help would be appreciated, if it can't be fixed, it's ok I can just have it say one thing. :)
I think you would do
function onChatted(msg, recipient, speaker) -- convert to all lower case local source = string.lower(speaker.Name) msg = string.lower(msg) if (msg == "dragon ball" or msg == "dragonball") then -- I think you meant to add or not a comma. door.CanCollide = false door.Transparency = 0.7 wait(5) door.CanCollide = true door.Transparency = 0 end end function onPlayerEntered(newPlayer) newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) end game.Players.ChildAdded:connect(onPlayerEntered)
Let me know if this fixes it.
In English, we say
-- THIS IS WRONG FYI if A is 1 or 2 then
However, in Lua, the order of operations (for good reason) makes that look like this:
if (A is 1) or (2) then
This is definitely NOT what you intended when you wrote like that:
We see that A is actually completely unrelated to the value 2 in this condition (and because of ho or
works in Lua, this statement will actually always evaluate to something true
-y, so this mistake actually makes the condition completely useless).
We instead, unfortunately, have to repeat the whole statement:
if (A is 1) or (A is 2) then
Which, in your specific case, would be written like this:
if msg == "dragon ball" or msg == "dragonball" then
There are slightly more powerful ways to do this which might prove useful, however. For instance, if you started by removing all spaces from msg
in the first place, the check for the space/unspaced versions would be unnecessary, since all spaces were removed. We would do this in the line that makes it lowercase:
msg = string.lower(msg):gsub("%s",""); -- %s is any space, we replace it with "" (nothing) -- thus removing any spaces.