Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My 'Check' function is not working properly?

Asked by
IcyEvil 260 Moderation Voter
6 years ago

I can't seem to figure out how to the 'check' function, the script was functional up until I got to making the check.

I am rusty so please forgive me if it is a simple issue, I haven't attempted deving for a good year.

script.Parent.Touched:connect(function(hit)
    if hit.Parent then
        local hum = hit.Parent:FindFirstChild("Humanoid")
        if not hum then
            print('Wasnt a humanoid')
        else
            local egg_plot = game.ServerStorage.Egg_Plot:Clone()
        egg_plot.Parent = game.Workspace
    function check()
        local already_in_workspace = game.Workspace.Egg_Plot
        if already_in_workspace.Parent == game.Workspace then
            egg_plot:Destroy()
        else
            print('there wasnt an Egg Plot in workspace')
        end
    end
check() 
        end
    end
end)

1 answer

Log in to vote
0
Answered by
tantec 305 Moderation Voter
6 years ago

You created a function inside of an if statement, you don't really need the function in the first place, and even if that did work, you have executed the function outside of the if statement you were intending it to be in.

script.Parent.Touched:connect(function(hit)
    if hit.Parent then
        local hum = hit.Parent:FindFirstChild("Humanoid")
        if not hum then
            print('Wasnt a humanoid')
        else
            local egg_plot = game.ServerStorage.Egg_Plot:Clone()
        egg_plot.Parent = game.Workspace
        local already_in_workspace = game.Workspace.Egg_Plot
        if already_in_workspace.Parent == game.Workspace then
            egg_plot:Destroy()
        else
            print('there wasnt an Egg Plot in workspace')
        end
    end 
        end
    end
end)

And that's all that it needed. Hope this helped!

0
It didn't work but I didnt notice I had ran the function outside of the if statement, thanks! IcyEvil 260 — 6y
Ad

Answer this question