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

My 'Check' function is not working properly?

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

✓ Accepted answer

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!

1 comment

0

It didn't work but I didnt notice I had ran the function outside of the if statement, thanks!

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