If you want it to be on the outside, you can make it so that the furthest parts that are still in the cylinder are kept.
Honestly i dont see why it isnt working
Except i dont see the purpose of the repeat until, can you explain?
I suggest calculating a random position by
Local bombPos = Button.Position + Vector3.new(math.random etc
I want it to be on the inside
i am repeating so it doenst calculate a pos outside
You dont need to if you set the random to a number smaller than the radius of the circle
well how do i calculate the pos in the circle
You said you want it to spawn outside.
I can’t help you unless you make up your mind.
Add the button position or circle position to the random vector
Wait I think I understand what you meant now, this is true. You will not need to use a while loop to get this running.
inside
This text will be blurred
The function detects parts in a part, so this will detect if it’s inside. This is what you want, right?
Workspace | Roblox Creator Documentation
If button is at 100,1,0 then
Button.Position + Vector3.new(math.random(-50,50), 0, math.random(-50,50))
Will return values in a 50 stud radius from the point 100,1,0
I realised this is a square sorry
does it have to be parented to the part or just near its position?
The function requires both to be a descendant of WorldRoot
.
But ur telling me where to position the button not the spawned part
No
The button will be in the middle of the circle right?
So adding this random vector to its position gives a position around the button
Which you can use for the bomb
BombPos = Button.Position + Vector3.new(math.random(-35,35), 0, math.random(-35,35))
There’s no need to set the bomb’s position to a random Vector3 until it’s within a certain radius. Instead, use the parametric equation to place a point at a random distance r and random angle theta away from the center coordinates.
This will be much a faster solution than selecting a random position and checking if it’s within 35 studs of Button.Position, since the randomizer only runs once per bomb instead of an unlimited number of times.
for i = 1, 20 do
local NewBomb = game.ReplicatedStorage.GroundBomb:Clone()
local randomAngle = math.random(0, 2*math.pi) --Random angle in radians.
local randomDistance = math.random(0, 35) --Random distance.
local x = Button.Position.X + randomDistance*math.sin(randomAngle) --The button's X coordinate is used to offset the value returned by r * sin(theta)
local z = Button.Position.Z + randomDistance*math.cos(randomAngle) --Ditto, but for Z and cos(theta)
NewBomb:PivotTo(CFrame.new(x, Button.Position.Y, z)) --Move the bomb's CFrame to the new random position.
NewBomb.Parent = workspace --Set parent to workspace so it actually spawns in.
end
Why is sin used on x and cos used on z