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

Why is this PARTIALLY doing my script?

script.Parent.Touched:connect(function()
	script.Parent:FindFirstChild("Humanoid")
	script.Parent.CanCollide = false
	if
		script.Parent:FindFirstChild("Humanoid") == false then
		script.Parent.CanCollide = true
	end
end)

Supposed to turn the brick's CanCollide to false if a Humanoid is touching it, and when the player is not on/in the brick, cancollide goes back to true.

All this script does is turn the canCollide to false and it stops there.

1 answer

You HAVE to check for the humanoid BEFORE ANYTHING ELSE.

script.Parent.Touched:connect(function()
	if script.Parent:FindFirstChild("Humanoid") then
		script.Parent.CanCollide = false
    elseif not script.Parent:FindFirstChild("Humanoid") then
        script.Parent.CanCollide = true
    end
end)

you didnt check for it. you just sent an empty request. it finds it but doesnt know what to do with that info

EDIT: So it sent the empty request and moved on to setting it to false, then checking for the other condition. (Note: elseif is better practice)

REEDIT:

script.Parent.CanCollide = true

script.Parent.Touched:connect(function(hit) -- oops forgot this important part
	if hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.CanCollide = false
    end
end)

script.Parent.TouchEnded:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.CanCollide = true
    end
end)

6 comments

0

Pretty sure you don't need not after elseif

0

Thanks!

0

it just makes more sense to me, you can use if thing == false but i like if not

0

Nvm, this doesn't work. It stays cancollided. It doesn't go to false, it stays true.

0

oooh, hold on

0

fixed i think

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