Kill Brick Exception

Hi! So I tweened a brick so when it comes at you, it kills you. But, I want to make an exception to this: if a part is parented to workspace, it will not do so (will not kill you.) Does anyone think they can help? Thanks.

Here is the script I have:

local hb = game.ReplicatedStorage.HB

script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		if hb.Parent == game.Workspace then return false end
		hit.Parent.Humanoid.Health = 0
	end
end)

That actually looks perfect, what is the problem you are having?

Oh no, I just wanted to see if there was any mistakes with my script! Thank you so much!

1 Like

I wanted to see if the “return false” was good in this type of situation.

Won’t this not kill them at all, because all characters are direct children of the Workspace?

I just copy the script from the Obby Roblox made, copy the script for the kill brick and add it in.

Actually I tested it, it does kill you if the hitbox is not parented to workspace

I would personally do it like this:

script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		if hb.Parent ~= workspace then
	    	 hit.Parent.Humanoid.Health = 0
        end
	end
end)

Or

script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		if hb.Parent == workspace then return end
	    hit.Parent.Humanoid.Health = 0
	end
end)

I mean this won’t shield them at all because if this is true

then this won’t be true:

because the part cannot be a direct child of both the workspace and the player’s character.

Thank you! I appreciate the help!

1 Like

What is the HB thing inside of ReplicatedStorage? Also for the check to not do anything if the part is a child of workspace, you can just do return end rather than return false end. Also you can use workspace instead of game.Workspace but that’s just personal preference

1 Like

It isnt of the players character. That’s a script in the kill brick, and the hitbox is a totally different brick.

1 Like

Thank you! Appreciate it!

asfasdfs

Oh I see, I’m so sorry I misread the script.

It’s okay lol, still thank you so much for your feedback!

1 Like

Wait hang on, I dont think the exception you did will never become true, since the parent of hb is ReliplicatedStorage, unless the parent is changed from another script

How may I change this then?

qghe8urhijnqe

Does another script change the parent of hb? Also what even is hb

Hitbox (a separate part). Also no, not as of right now.

Then if nothing changes its parent then I dont think that condition will ever become true, since the parent is always going to be ReplicatedStorage, if so, I dont think you need that condition for now, you can comment it out for now till something changes the parent

Here’s how I would do the code

script.Parent.Touched:Connect(function(hit)
	local char = hit.Parent -- Made a variable since I'm using hit.Parent more than once, personal preference
	if game.Players:GetPlayerFromCharacter(char) then
		--if hb.Parent == workspace then return end
	    char.Humanoid.Health = 0
	end
end)