I tried to make a spawner that spawns a tool (a pink cube) randomly in a radius around the spawner but the cube doesnt move and doesnt spawn randomly
--// Variables local cframeX = workspace.testSpawner.Position.X local cframeY = workspace.testSpawner.Position.Y local cframeZ = workspace.testSpawner.Position.Z local randomspawn = Vector3(math.random(cframeX - 20, cframeX + 20), cframeY + 20, math.random(cframeZ -20, cframeZ + 20)) local randomspawntimer = math.random(5, 8) local numb = 0 local canSpawn = true local Workspace = game.Workspace local PinkCube = Workspace:WaitForChild('PinkCube') local PinkSpawner = workspace.testSpawner --// Main while true do if canSpawn then if numb <= 25 then canSpawn = false local PCC = PinkCube:Clone() PCC.Parent = PinkSpawner PCC.Handle.Position = Vector3(math.random(cframeX - 20, cframeX + 20), cframeY + 20, math.random(cframeZ -20, cframeZ + 20)) wait(randomspawntimer) canSpawn = true numb = numb + 1 end end end end
You actually have the script working properly!
You just missed the .new on your Vector3 values. (Change them to Vector3.new(x, y, z) ) And then you have one too many ends in there.
The way to fix that is just to remove your second to last "end" from the while loop.
The fixed code looks like this if you want to just copy paste it.
--// Variables local PinkSpawner = workspace:FindFirstChild("testSpawner") local cframeX = PinkSpawner.Position.X local cframeY = PinkSpawner.Position.Y local cframeZ = PinkSpawner.Position.Z local randomspawn = Vector3.new(math.random(cframeX - 20, cframeX + 20), cframeY + 20, math.random(cframeZ -20, cframeZ + 20)) local randomspawntimer = math.random(5, 8) local numb = 0 local canSpawn = true local PinkCube = workspace:WaitForChild('PinkCube') --// Main while true do if canSpawn then if numb <= 25 then canSpawn = false local PCC = PinkCube:Clone() PCC.Parent = PinkSpawner PCC.Handle.Position = Vector3.new(math.random(cframeX - 20, cframeX + 20), cframeY + 20, math.random(cframeZ -20, cframeZ + 20)) wait(randomspawntimer) canSpawn = true numb = numb + 1 end end end
(I also removed some of the unnecessary code. (i.e., the workspace.testSpawner.Position.X,Y,Z) )
If this helped, don't forget to mark this as the answer so people know that it's solved.
If you have any other questions, or questions about anything above feel free to ask!