I want to make a spawn system but for some reason i cant move the cloned Item to the spawn position,how can i fix that?
local Water = workspace:WaitForChild("ItemSpawns").Items:WaitForChild("Water")
local Itemspawns = script.Parent.Parent
local cooldown = 5
local spawnpos = nil
local function randomize()
local random = 2 --math.random(2)
if random == 1 then
local spawnpos = Itemspawns:WaitForChild("ItemSpawnIdk")
elseif random == 2 then
local spawnpos = Itemspawns:WaitForChild("ItemSpawnerLemo")
elseif random == 3 then
local spawnpos = Itemspawns:WaitForChild("ItemSpawnYes")
elseif random == 4 then
local spawnpos = Itemspawns:WaitForChild("ItemSpawnNo")
end
local chance = 2 --math.random(1,6)
if chance < 3 then
local item = 0 -- item = math.random(1,4)
if item == 0 then
local Item = Water:Clone()
print("Cloned the test item")
Item.Parent = workspace
Item:WaitForChild("Handle").Position = spawnpos.Position + Vector3.new(0,0.5,0)
print("Set its position")
end
end
task.wait(cooldown)
randomize()
end
randomize()
are you getting any errors? Do you see the object in the workspace? Do you see all the print values?
If you see the object in the workspace while playing in studio, then swap to server and see if you see the object still, if so, select it and press f, see where itâs at, and check the properties in the explorer while youâre there. Should add a print value inside your script under âCloned the test itemâ which prints out the spawnpos value to see what it states.
Oh, also a side not, youâre calling in each of those randoms, âlocal spawnposâ but you already initialized it outside those statements, and those variables (i believe) would not be accessible outside of that scope. Instead just remove the âLocalâ part before each of the spawnpos variables inside the if statements (not the very first one) as that could be a part of your problem
then itâs probably the spawnpos as this would be considered nil at that line from what i stated earlier with the local scopesâŚ
Try this
local Water = workspace:WaitForChild("ItemSpawns").Items:WaitForChild("Water")
local Itemspawns = script.Parent.Parent
local cooldown = 5
local spawnpos = nil
local function randomize()
local random = 2 --math.random(2)
if random == 1 then
spawnpos = Itemspawns:WaitForChild("ItemSpawnIdk")
elseif random == 2 then
spawnpos = Itemspawns:WaitForChild("ItemSpawnerLemo")
elseif random == 3 then
spawnpos = Itemspawns:WaitForChild("ItemSpawnYes")
elseif random == 4 then
spawnpos = Itemspawns:WaitForChild("ItemSpawnNo")
end
local chance = 2 --math.random(1,6)
if chance < 3 then
local item = 0 -- item = math.random(1,4)
if item == 0 then
local Item = Water:Clone()
print("Cloned the test item")
Item.Parent = workspace
Item:WaitForChild("Handle").Position = spawnpos.Position + Vector3.new(0,0.5,0)
print("Set its position")
end
end
task.wait(cooldown)
randomize()
end
randomize()