Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I select a random position inbetween two parts?

Asked by 4 years ago

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")


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)) mixgingengerina10 223 — 4y
0
I tried that, although I got this error: Workspace.DrizzleRainCloud.RainGenerator:12: Expected ')' (to close '(' at column 81), got ',' soccerstardance251 29 — 4y
0
I updated my comment mixgingengerina10 223 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

0
It works thanks! soccerstardance251 29 — 4y
Ad

Answer this question