How to clone part to a random position in the bounds of the RoadModel.Road (on workspace)

  1. What do you want to achieve? Clone part to a random position but not in all the game only in the RoadModel.Road
  2. What is the issue? idk how to clone it to a random position (in the RoadModel.Road)
    This is a video so I want to clone the part on this road only (I can’t upload the video idk why)
  3. What solutions have you tried so far? I saw some topics about that but I didn’t understand

this is my clone script so who can edit it and make the Fire clone to a random position in the bounds of the RoadModel.Road

local Fire = game.ReplicatedStorage.Fire
local Clone = Fire:Clone()
Clone.Parent = workspace
1 Like

Can you be more specific? What does your road look like, what were the other topics, and what is this for?

2 Likes

this is a link for topic that I saw

I want to clone a part to a random position inside the RoadModel.Road so not on all the game only on the RoadModel.Road so I want to clone it on RoadModel.Road its hard to explain

1 Like

I’m assuming that “RoadModel.Road” is an instance in the workspace?

1 Like

Yes its on workspace

(More Characters)

1 Like

Move the part’s CFrame to a random X axis an Z axis near the road.

local RandomRange = math.random(-5,5) -- Generates a random number in between -5 and 5
Part.CFrame = Road.CFrame * CFrame.new(RandomRange,1,RandomRange ) 
1 Like

this is my clone script so who can edit it and make the Fire clone to a random position in the bounds of the RoadModel.Road

local Fire = game.ReplicatedStorage.Fire
local Clone = Fire:Clone()
Clone.Parent = workspace
1 Like

this will only return whole numbers
try this

local RandomRange = Random.new():NextNumber(-5, 5) -- Generates a random number in between -5 and 5
Part.CFrame *= CFrame.new(RandomRange, 1, RandomRange) 
2 Likes

And the issue you’re having is, if I’m interpreting what you said correctly, you want to spawn something only on the road and not off of it? If that’s the case, the other topic you sent above would work. I’ll attempt to explain it.

local clonedObj = crop1:Clone() --Clones the object
local extents = dirt.Size.X/2 --This is the width of the road divided by two (see image below)
local x = math.random(-extents,extents) --This produces a value that is between the far left and far right sides of the road
clonedObj.Position = dirt.Position + Vector3.new(x,1.8,0) --This places the clonedObj to be directly on the road, but uses the x value to place it anywhere along the width (if that makes sense)
clonedObj.Parent = dirt --Sets the parent

I hope that clears it up a little?

1 Like

read this uh why no one understand

1 Like

I don’t see why what I posted above doesn’t work, set the Clone’s position using the script above, and that should make it so that the clone doesn’t go off the road

they could just be confused about it

I want to clone a part that named Fire to a random position but in the bounds of RoadModel.Road

If your looking to make sure its in the bounds of the model, then try making use of the GetBoundingBox method.

You’re right, sorry: @MONSTERGAMES3609, when you clone the part, set the position like so:

local Fire = game.ReplicatedStorage.Fire
local Clone = Fire:Clone()

local extents = Clone.Size.X/2
local bounds = math.random(-extents, extents)
Clone.Position = Road.Position + Vector3.new(x,Road.Position.Y,0)

Clone.Parent = workspace

Let me know if that works or not

Some pictures of the road


Looks you just need to randomize the Z bounds of that round.

this not work its only cloned to the mid of the road not in a random position in the bounds f road

I see… Try this

local Fire = game.ReplicatedStorage.Fire
local Clone = Fire:Clone()

local boundsX = math.random(-Road.Size.X/2, Road.Size.X/2)
local boundsZ = math.random(-Road.Size.Z/2,Road.Size.Z/2)

Clone.Position = Road.Position + Vector3.new(boundsX,Road.Position.Y,boundsZ)

Clone.Parent = workspace

Its work but the Fire spawn under the road