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 months 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? p0etic 5049 — 5mo
0
Yeh Deinonychusaurus 21 — 5mo

1 answer

Log in to vote
1
Answered by
herrtt 387 Moderation Voter
5 months ago
Edited 5 months 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 — 5mo
Ad

Answer this question