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

How do i check if theres a part, and if there isn't it functions??

soo im trying to make a script where if there is not a curtain part it functions this is what i've tried to do but it just errors cuz it can't find the part so the rest of the script won't play

if game.Workspace["Wheat Big"]:FindFirstChildOfClass('Weld') == nil then
script.Parent:Remove()
end

2 comments

0

which part can't it find? Wheat Big?

0

Yeh

1 answer

✓ Accepted answer

The question was quite unclear, but Ive tried to understand.

You should first check if "Wheat Big" is in workspace. Otherwise it will error as it is not in workspace (aka. nil). After that you can check if the Weld is inside "Wheat Big" like I did here. I hope this clears up some stuff.

local Wheat = workspace:FindFirstChild("Wheat Big")
if Wheat then
	local Weld = Wheat:FindFirstChild("Weld")
	if Weld then
		print("Found Weld!")
		script.Parent:Destroy()
	else
		print("Weld does not exist!")
	end
else
	print("Wheat Big does not exist!")
end

(if this seemed to work an upvote would be appreciated)

1 comment

0

Thanks!

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