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

How to make an if inside a if?

Asked by 5 years ago
Edited 5 years ago

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)

0
Instead of using a global variable I suggest using bool values and then try and see if it's still a problem. johndeer2233 439 — 5y
0
I try to stay away from global variables to be honest johndeer2233 439 — 5y

1 answer

Log in to vote
0
Answered by
CjayPlyz 643 Moderation Voter
5 years ago
Edited 5 years ago

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?

0
Thanks, i'll try it out. User#27525 1 — 5y
0
I'll acept the answer if it work. User#27525 1 — 5y
0
Still don't work. User#27525 1 — 5y
0
also, if it doesn't work can you show the global function CjayPlyz 643 — 5y
View all comments (5 more)
0
What do you mean? User#27525 1 — 5y
0
Edit the question and insert a code, particularly the part where the global function is. CjayPlyz 643 — 5y
0
You can find the edit button just bellow the comments of the question (not the answers) CjayPlyz 643 — 5y
0
nvm found out the error User#27525 1 — 5y
0
oh.. good for you then CjayPlyz 643 — 5y
Ad

Answer this question