Hello, I'm currently working in a little RNG-based system to place objects within a specific range (in this case, as long as it is in bounds of a specific part), this means that the X and Z are going to be random, but the Y is going to be constant.
My expected result is for parts to be scattered randomly around the selected field, but I messed something up, and for some reason, random X works, and while Z kind of does, the differences in Z coordinates are very minuscule.
Result of my current script (image link): https://cdn.discordapp.com/attachments/482924987288780801/765527140174528542/unknown.png
Current script (generation happens in a client-sided ModuleScript):
generator.generate = function(Slide, Amount) local SlideSpawn = Slide:FindFirstChild("Spawn"); local SlideEdgeX = Vector2.new((SlideSpawn.Position - Vector3.new(SlideSpawn.Size.X/2, 0, 0)).X, (SlideSpawn.Position + Vector3.new(SlideSpawn.Size.X/2, 0, 0)).X); local SlideEdgeY = Vector2.new((SlideSpawn.Position - Vector3.new(0, 0, SlideSpawn.Size.Y/2)).Z, (SlideSpawn.Position + Vector3.new(0, 0, SlideSpawn.Size.Y/2)).Z); for i = 0, Amount do local rng = Random.new() local ToPaste = Instance.new("Part"); ToPaste.Size = Vector3.new(1, 1, 1); ToPaste.Anchored = true; ToPaste.Parent = Slide; local RanX = rng:NextNumber(SlideEdgeX.X, SlideEdgeX.Y); local RanZ = rng:NextNumber(SlideEdgeY.X, SlideEdgeY.Y); print(SlideEdgeY.X, SlideEdgeY.Y); ToPaste.Position = Vector3.new(RanX, SlideSpawn.Position.Y, RanZ); end end
Managed to correct the issue myself, not sure what exactly I did, but it worked. The two modified lines:
local SlideEdgeX = Vector2.new((SlideSpawn.Position - Vector3.new(SlideFromCenter, 0, 0)).X, (SlideSpawn.Position + Vector3.new(SlideFromCenter, 0, 0)).X); local SlideEdgeY = Vector2.new((SlideSpawn.Position - Vector3.new(0, 0, SlideFromCenter)).Z, (SlideSpawn.Position + Vector3.new(0, 0, SlideFromCenter)).Z);