Part spawner after check

Today I tried making one of my first scripts without any help. The idea is a part that is anchored to the ground and transparent. The part checks to see if another part is on top of it. If the check determines the part is not on the original part, then it spawns the second part, which happens to be a treasure chest.

So basically a chest spawner that will only spawn a chest if the chest is not there.


local function check()
	local check = script.Parent:FindFirstChild("Chest Small")
	if not check then
		wait(5)
		game.ReplicatedStorage.Tools["Chest Small"]:Clone().Parent = script.Parent
	end
end

while true do
	wait(2)
	check()
end

Yhe problem is it does not actually work. haha anyone able to help me with this?

Still trying to make a part spawner work. I have changed this many times since I made the post and still failing.

Try changing if not check then to if check then.

Is the chest going into workspace and the part you wanted it go to? Or is not going to the parent you set it to.

trying to get the chest to spawn on the part with the script in it. But it doesnt spawn anywhere.

Thats because you didn’t set its parent to the workspace and define its position.
So make the cloned chest’s parent to the workspace, and set its position where you want it to spawn

If I just put the part on in the workspace would that work?

yes (asdklashdlkasjdkasdkakskljd )

I put a part straight into the workspace, Added this script an nothing happened. Still does not spawn the chest on the part.