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

can you put a if in a if statement and help with checking if player has pressed e?

in my game i am trying to make if a player is on one part then if they press a key a function will be triggered after multiple testing i have not succeeded, so i have two questions can you put a if inside a if statement (this is the way i have been trying to use) and if yes/no how can i fix it

this is the code i have been using i removed the if statement inside the if statement i was using because i thought it wasn't necessary if you want it please ask.

debounce = false

script.Parent.Touched:connect(function(hit)

 if not debounce then
	
        debounce = true
	    if(hit.Parent:FindFirstChild("Humanoid")~=nil)then
		
		
		
		
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local sound = script.Parent.Sound:Clone()
        sound.Parent = player.PlayerGui
		sound:Play()
		wait(5)
		local player = game.Players.LocalPlayer
        local mouse = player:GetMouse()
 
	    mouse.KeyDown:connect(function(key)
			
			if key == "e" then
				print("diditwork")
                
            end
        end)

     end
    debounce = false
end

end)

3 comments

0

yes, you can nest your if statements. You can also try complex conditionals (and/or). Also, please re-enter your code, there is no if-statements provided and its not yet formatted.

0

i tried simplifying it and i realize now that is i code a tried but decided not to use here is the one i'm trying to get to work 

0

i put it in the edit

2 answers

✓ Accepted answer

Yes, you can add an if statement inside one. I'll give you a quick example:

if 2+2==4 then
	if 1+1==2 then
		print("all was correct")
	end
end

1 comment

0

Cool thank you

2 comments

0

this kinda helps thanks

0

why downvote?

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