How to check if an item is already spawned?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make it so it checks in a set amount of time if there is already an child in a folder and if there isn’t a child then it will spawn a new item

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that the spawner will not spawn a new item.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried modifying the script in a different way to check if the part is present as a child in a folder.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Storage = script.Parent.Storage
local Spawner = script.Parent
local Value = script.SelectedItem.Value

script.Parent.Transparency = 1

while task.wait() do
	if Storage:FindFirstChildWhichIsA("Accessory") then
		return
	else
		local Clone = Value:Clone()
		Clone.Parent = Storage
		Clone:FindFirstChild("Handle").CFrame = spawn.CFrame
	end
end

image

1 Like

you can’t clone a proprety of a value…

I didn’t know about that until now
i’ll change the script up to not include the value

also your selecteditem is not a… tool…it’s a value so it doesn’t have a Handle

what type of value is SelectedItem? is it an object value?

It’s a number value, I know this because it has a # next to the name.

@EstebanMARIN17 what you are going to want to do here is you can keep that value but turn it into a string value or something and what you will want to do, keep all of your tools inside of a folder, I keep mind in a folder in ServerStorage.

After your loop has restarted and noticed that there was no tool simply find the tool where the name matches the values value like so:

local clone = folder:FindFirstChild(tostring(value.Value)):Clone()

I would personally make sure that there is a tool called that value before doing anything else just to ensure that there will be no errors or you can simply wrap in it a task.spawn(function()

Also no reason for doing that whole check to add unnecessary lines of code. Simply do as so:

while task.wait() do
	if not Storage:FindFirstChildWhichIsA("Accessory") then
		if not folder:FindFirstChild(tostring(value.Value)) then return false; end
		local Clone = folder:FindFirstChild(tostring(value.Value)):Clone()
		Clone.Parent = Storage
		Clone:FindFirstChild("Handle").CFrame = spawn.CFrame
	end
end

I personally would also desyncronize this via debug just so that it is on it’s own thread with its own worker

1 Like

Yeah SelectedItem is a object value

Double check that it is an object value, also is the SelectedItem you are trying to clone a group model or an individual part? If it is an individual part, I tested this script and it works for me:

local Storage = script.Parent.Storage
local Spawner = script.Parent
local Value = script.SelectedItem.Value

script.Parent.Transparency = 1

while task.wait() do
	if Storage:FindFirstChildWhichIsA("Accessory") then
		return
	else
		local Clone = Value:Clone()
		Clone.Parent = Storage
		Clone.CFrame = Spawner.CFrame + Vector3.new(0, 5, 0)
	end
end

However if it is a model then this won’t work