New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 5 days ago

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
0
which part can't it find? Wheat Big? royaltoe 3678 — 5d
0
Yeh Deinonychusaurus 21 — 4d

1 answer

Log in to vote
1
Answered by
herrtt 226 Moderation Voter
5 days ago
Edited 5 days ago

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)

0
Thanks! Deinonychusaurus 21 — 4d
Ad

Answer this question