So this test is very simple, with a part called “White” in replicated storage being cloned.
Someone gave me this script to randomize its position inside of a part, but it only works for bigger parts.
I have read other topics, but they’re not too similar to my problem.
Code:
local part = script.Parent
local PS = part.Size
while wait() do
local white = game.ReplicatedStorage.White:Clone()
white.CFrame = part.CFrame * CFrame.new(math.random(-PS.X/2,PS.X/2),math.random(-PS.Y/2,PS.Y/2),math.random(-PS.Z/2,PS.Z/2))
print(math.random(-PS.X/2,PS.X/2),math.random(-PS.Y/2,PS.Y/2),math.random(-PS.Z/2,PS.Z/2))
white.Parent = workspace
end
Also look at the y coordinate, it doesn’t change for some reason
I think I kinda figured out how to use that, but it looks the exact same as before.
local part = script.Parent
local PS = part.Size
while wait() do
local white = game.ReplicatedStorage.White:Clone()
local random = Random.new()
local randomNumberX = random:NextInteger(-PS.X/2,PS.X/2)
local randomNumberY = random:NextInteger(-PS.Y/2,PS.Y/2)
local randomNumberZ = random:NextInteger(-PS.Z/2,PS.Z/2)
white.CFrame = part.CFrame * CFrame.new(randomNumberX,randomNumberY,randomNumberZ)
print(randomNumberX,randomNumberY,randomNumberZ)
white.Parent = workspace
end
You don’t need to make a randomNumber variable, here is Random.new() in your script:
local ran = Random.new()
local part = script.Parent
local PS = part.Size
while wait() do
local white = game.ReplicatedStorage.White:Clone()
white.CFrame = part.CFrame * CFrame.new(rand:NextInteger(-PS.X/2,PS.X/2),math.random(-PS.Y/2,PS.Y/2),math.random(-PS.Z/2,PS.Z/2))
print(math.random(-PS.X/2,PS.X/2),math.random(-PS.Y/2,PS.Y/2),math.random(-PS.Z/2,PS.Z/2))
white.Parent = workspace
end
You could multiple the given math.random(-PS.X/2,PS.X/2) to math.random since this is always a 0 to 1, something like this maybe math.random(-PS.X/2,PS.X/2) * math.random() or Random.new():NextNumber(-PS.X/2,PS.X/2)
Well guys, thank you so much. Yall helped me finally get the solution.
Incase anyone finds this post and needs it, here it is:
local part = script.Parent
local PS = part.Size
while wait() do
local white = game.ReplicatedStorage.White:Clone()
local PS = part.Size
white.CFrame = part.CFrame * CFrame.new(Random.new():NextNumber(-PS.X/2,PS.X/2),Random.new():NextNumber(-PS.Y/2,PS.Y/2),Random.new():NextNumber(-PS.Z/2,PS.Z/2))
print(Random.new():NextNumber(-PS.X/2,PS.X/2),Random.new():NextNumber(-PS.Y/2,PS.Y/2),Random.new():NextNumber(-PS.Z/2,PS.Z/2))
white.Parent = workspace
end