#Ending If statements

87 messages · Page 1 of 1 (latest)

devout snow
#

Region.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        return nil
        
    elseif hit.Parent:FindFirstChild(part) then
        return nil
        
    elseif hit.Parent:FindFirstChild(game.Workspace.Baseplate) then
        return nil
    else
        Tween:Play()
    end
end)

can anyone tell me what im supposed to use instead of return nil as that doesnt seem to work

stuck gale
#

Just return

#

No need to put nil

devout snow
#

it still fires

stuck gale
#

What fires?

devout snow
#

the tween

stuck gale
#

Print before the return

#

See if it prints

devout snow
#

none of it printed

#

i do not understand whats happeneing

stuck gale
#

If it didn't print, it goes to the else

#

Something is wrong with your if statement

devout snow
#

thats why i said how do i end the if statement before it gets to the else

stuck gale
#

Huh

#

That makes no sense

devout snow
#

think of it like using a break in a loop

#

how can i do that with an if

fallen mural
#

Region.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") and not hit.Parent:FindFirstChild(part) and not hit.Parent:FindFirstChild(game.Workspace.Baseplate) and not hit.Parent:FindFirstChild(game.Workspace.Baseplate) then
Tween:Play()
end
end)

mystic sunBOT
#

studio** You are now Level 1! **studio

stuck gale
#

When do you want to stop it?

fallen mural
#

i think this would work

devout snow
#

when any of the three previous conditions are true

fallen mural
#

sorry the way discord made it

#

would that work for u?

stuck gale
#

Otherwise, it would just stop it perfectly

devout snow
#

which is whats confusing me because the if statement wont fire unless something touches the region

stuck gale
#

Your last elseif makes no sense anyways. What are you even checking?

devout snow
#

those three are the only thing that could be touching it

stuck gale
#

Print hit

fallen mural
#

wait what are you checking?

stuck gale
#

Let's see what is actually hitting it

stuck gale
devout snow
stuck gale
#

He's like checking if it's in the workspace, but in a difficult way

devout snow
#

that makes no sense 😭

fallen mural
#

homie what are you trying to do?

stuck gale
#

Fr

#

Your script makes no sense lol

#

Just explain what you're trying to do and we'll help you improve the code

fallen mural
#

what are you trying to get to happen when the part is touched

devout snow
#

basically something enters a trash can and the trash can floats to another position

#

thats what the tween is for

stuck gale
#

Ah

fallen mural
#

does it matter what the trash can touches?

#

does it hae to be a player

#

a specific part

stuck gale
#

Yes

#

Because this can be done way easier then

#

What's your requirement

devout snow
#

im trying to make it so if it touches a player, the baseplate, or the actual model it wont run

stuck gale
#

And anything else would run?

devout snow
#

exactly

stuck gale
#

Ok

#

Say

devout snow
#

but there lies the problem

#

its touching the model and basepate and is runnin

fallen mural
#

Region.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") and not hit.Name == "Baseplate" and not hit == part then
Tween:Play()
end
end)

stuck gale
#

if not hit.Parent:FindFirstChild("Humanoid") and not hit.Name == "Baseplate" and not hit == region then

stuck gale
#

Everytjing*

#

Tell me if it works 🙂

#

Oh

devout snow
#

they both give me errors 😅

fallen mural
#

what are the errors?

stuck gale
#

And the last can be "hit ~= region"

mystic sunBOT
#

studio** You are now Level 8! **studio

stuck gale
#

How did I mess that up 💀 Am I high?

devout snow
#

💀

stuck gale
#

That's the correct way

#

Sorry

fallen mural
#

Region.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") and hit.Name ~= "Baseplate" and hit ~= part then
Tween:Play()
end
end)

#

fixed

stuck gale
#

I fr don't know how I messed that up

devout snow
#

i dont usually use not in if statements i should probably use it more

fallen mural
#

mhm,

devout snow
#

btw works perfectly thx

stuck gale
#

Great

fallen mural
#

😎

devout snow
#

using not changed my long code into a short better one

#

ill def incorporate it more

stuck gale
#

Yes

queen minnow