Random position inside block script not working

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 a part from replicated storage be cloned into the workspace in a random position
  2. What is the issue? Include screenshots / videos if possible!
    does not work, even when I tested with putting prints after each command. There is no errors in output.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried most solutions, and i have looked on dev hub. this code is my third revamp of trying to make it work
    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!

while true do

local x = game.Workspace.corner1.Position.X + math.random(-game.Workspace.corner1.Size.X/2,game.Workspace.corner1.Size.X/2)

local y = game.Workspace.corner1.Position.Y + math.random(-game.Workspace.corner1.Size.Y/2,game.Workspace.corner1.Size.Y/2)

local z = game.Workspace.corner1.Position.Z + math.random(-game.Workspace.corner1.Size.Z/2,game.Workspace.corner1.Size.Z/2)

game.ReplicatedStorage.Bonezones.DusttrustSlash.Part:Clone().Position = Vector3.new(x,y,z)

wait()

You didnt parent the clone to workspace.

1 Like

you have to give your clone a variable

local clone = game.ReplicatedStorage.Bonezones.DusttrustSlash.Part:Clone()
clone.Position = Vector3.new(x,y,z)
clone.Parent = workspace

also you didn’t parent it to workspace like Decablocks said

1 Like

Ok ill try it, I just noticed my scripts all wonky on this, its in a while true do loop.

Also you should define your variables first to avoid making unnecessarily long lines.

local RepStorage = game:GetService("ReplicatedStorage")

local Corner1 = game.Workspace.corner1
local Part = RepStorage.Bonezones.DusttrustSlash.Part

while true do
   local XSize = Corner1.Size.X/2
   local YSize = Corner1.Size.Y/2
   local ZSize = Corner1.Size.Z/2

   local newPart = Part:Clone()
   newPart.Position = Corner1.Position + Vector3.new(
      math.random(-XSize, XSize),
      math.random(-YSize, YSize),
      math.random(-ZSize, ZSize),
   )

   newPart.Parent = game.Workspace
   task.wait()
end
1 Like