Why does this line of code work compared to this? (beginner scripter)

Hey guys I’m new to scripting so I’m a HUGE newbie when it comes to this profession but I’m learning so you’ll be seeing me a bunch of times on this topic. Anyways so I was wondering while I was just messing around trying to make a code that I learned from a few videos making a part unanchored after a player touches it. I managed to get the script to workout how I wanted it to be sort of but I was wondering why is it that I needed to change the line to. Also the first image is the code that is working but the second image is what wasn’t working.

if hum and Fallingobject.Anchored == true then

from the original line

if hum == true then


Humanoid or your hum is not a bool value meaning it isnt something that is true or false… so hum == true doesnt register.

In the line where it does work you use it correctly by saying “if hum then…” because its like saying if humanoid exists then…

If you had changed it to this it would not work anymore:

if hum == true and FallingObject.Anchored == true then

Edit: im not strong in scripting so if im wrong please someone correct me.


Roblox can teach you on how to make a fading trap

local isTouched = false
local function fade()
	if not isTouched then
		isTouched = true
		for count = 1, 10 do
		    platform.Transparency = count / 10
		platform.CanCollide = false
		platform.CanCollide = true
		platform.Transparency = 0
		isTouched = false

But I believe this is the script you are trying to make

function onHit(hit)
	local human = hit.Parent:findFirstChild("Humanoid")
	if (human ~= nil) and debounce == false then
 		debounce = true
		script.Parent.Anchored = false
		debounce = false


Let me know if you find any errors. I just made this up so it might not work

Oh I see now! I had no knowledge of the fact that the hum wasn’t a boolean. Thanks for that this was a lot simpler and a great understanding for me.

1 Like