Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I select a random position inbetween two parts?

On line 12, my code isn't working. How can I make it so it picks a random position in between the start and end parts? (Part name "Start" and part named "End"

This is my error: Workspace.DrizzleRainCloud.RainGenerator:12: bad argument #2 (interval is empty)

currentDroplet = 0


while true do
	--Creates the droplet
	droplet = Instance.new("Part")
	--print("Instanced a the droplet")
	--Sets the droplet's properties
	droplet.BrickColor = BrickColor.new("Toothpaste") or BrickColor.new("Teal")
	local start = game.Workspace.Start
	local xend = game.Workspace.End
	droplet.Position = Vector3.new(math.random(start.Position.X, xend.Position.X)(math.random(start.Position.Y, xend.Position.Y)(math.random(start.Position.Z, xend.Position.Z))))
	droplet.Anchored = true
	droplet.Size = Vector3.new(1, 2, 1)
	droplet.Transparency = 0.8
	currentDroplet = currentDroplet + 1
	droplet.Name = "Droplet"..currentDroplet
	wait(.5)
	droplet.Anchored = false
	droplet.Parent = script.Parent
	droplet.CanCollide = false
	--print("Set the droplet's properties")
	if currentDroplet <=50 then
		droplet.Parent = script.Parent["Droplets1-50"]
		--print(droplet.Name.." has been placed in the 1-50 folder")
	elseif currentDroplet > 50 and currentDroplet <= 100 then
		droplet.Parent = script.Parent["Droplets51-100"]
		--print(droplet.Name.." has been placed in the 51-100 folder")
	elseif currentDroplet > 100 and currentDroplet <= 150 then
		droplet.Parent = script.Parent["Droplets101-150"]
		--print(droplet.Name.." has been placed in the 101-150 folder")
	elseif currentDroplet >= 151 then
		break
	end
	
end

print("Break")


3 comments

0

You forgot commas. Vector3.new(math.random(start.Position.X, xend.Position.X), math.random(start.Position.Y, xend.Position.Y), math.random(start.Position.Z, xend.Position.Z))

0

I tried that, although I got this error: Workspace.DrizzleRainCloud.RainGenerator:12: Expected ')' (to close '(' at column 81), got ','

0

I updated my comment

1 answer

✓ Accepted answer

bro your thinking this too hard

local pos = start.Position:Lerp(xend.Position, math.random(1, 100) / 100)
droplet.Position = pos

All you gotta do is get a random percentage of a lerp and place it there. simple

1 comment

0

It works thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.