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

is there a less complex way of coding a damaging brick, with out the use of findfirstchild?

i'm a bit new, but when it comes to making a brick do damage, the only answers i've gotten is to use this script;

script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then hit.Parent:Breakjoints() end end)

is there a simpler way of coding this? or do i have to use FindFirstChild? also can functions have parents? if so what classifies as a parent for it?

1 comment

0

Please, paste code in Code block next time. In this case, FindFirctChild function used for check if a part that touched your part was a part of player. So then the answer for your question depends on what exactly you need.

2 answers

Yes, it also is better for your code to do this: instead of using "hit.Parent:FindFirstChild("Humanoid")" you can do "if hit.Parent.Humanoid" which is both faster for your code to do and easier for you to write.

And no, functions cannot have parents as they aren't objects themselves; they are variables.

If you have any questions or issues contact me. ;)

2 comments

0

Actually not, because if it hits an object it will error, which will stop the whole script. The primary objective of "FindFirstChild" is checking if the player has it; if not, the code will still run. So the fastest method is using "FindFirstChild", according to professional scripters.

0

^^^ this is both right and wrong. The stopping the script part is right but he's thinking of a pcall not FindFirstChild. No professional is explain FindFirstChild doing a pcall's job.

I'm not sure at all if this would work or not but maybe u can give it a try

script.Parent.Touched:Connect(function(hit)
	local hum
	local suc, err = pcall(function()
		hum = hit.Parent.Humanoid
	end)
	if suc then
		hit.Parent:BreakJoints()
	else
		warn(err)
	end
end)

1 comment

0

u can also use FindFirstChildOfClass()

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