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

How to make an if inside a if?

I know that the tittle may be a bit confusing but i'll explain. I'm trying to make a script that only fires when the player is pressing W and _G name is set to "ON". That's the script:

game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.W and _G.Switch == "ON" then

I don't know why it's not executing, and when i remove _G part it works well. I think that the error is in the second line, can someone help please?

(sorry for the bad english, it's not my primary language)

2 comments

0

Instead of using a global variable I suggest using bool values and then try and see if it's still a problem.

0

I try to stay away from global variables to be honest

1 answer

✓ Accepted answer

I don't really see anything wrong with the code, but you can try this one.

if input.KeyCode == Enum.KeyCode.W then
	if _G.Switch == "ON" then
	end
end

If it doesn't work then instead of using string values "ON" or "OFF" try changing it with bool values "true" or "false", and try to stay away from global functions or try to find a way to not use it. also can you show the whole code or particularly where it has to do something with the _G.Switch?

9 comments

0

Thanks, i'll try it out.

0

I'll acept the answer if it work.

0

Still don't work.

0

also, if it doesn't work can you show the global function

0

What do you mean?

0

Edit the question and insert a code, particularly the part where the global function is.

0

You can find the edit button just bellow the comments of the question (not the answers)

0

nvm found out the error

0

oh.. good for you then

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