I am trying to make a script that will connect a function to event. The function is supposed to make a wall made up of about 100 parts to seperate and go in random directions.
local TweenService = game:GetService("TweenService")
local function WallCoverRandomPosTween(Part, Min, Max, Modifier)
local IsDeleted = math.random(1, 3)
if IsDeleted == 1 then
local NewPosition = Vector3.new(Vector3.new(Part.Position.X + math.random(Min, Max) * Modifier, Part.Position.Y + math.random(Min, Max) * Modifier, Part.Position.Z + math.random(Min, Max)) * Modifier)
local NewOrientaton = Vector3.new(math.random(1, 360), math.random(1, 360), math.random(1, 360))
TweenService:Create(Part, TweenInfo.new(2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), {Position = NewPosition, Orientation = NewOrientaton}):Play()
else
Part:Destroy()
end
end
game.ServerStorage.OpenWall.Event:Connect(function()
for i, part in pairs(workspace.WallCover:GetChildren()) do
WallCoverRandomPosTween(part, -7, 7, 1)
end
end)
But I am having a very strange problem. Everything goes to the exact same position which turns out to be (0, 0, 0) and forms a weird blob. Here is the video: robloxapp-20230204-1446578.wmv (1.8 MB)
--//Services
local ServerStorage = game:GetService("ServerStorage")
local TweenService = game:GetService("TweenService")
--//Controls
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0)
--//Functions
local function WallCoverRandomPosTween(Part, Min, Max, Modifier)
local IsDeleted = Random.new():NextInteger(1, 3)
if IsDeleted == 1 then
local NewPosition = Vector3.new(Part.Position.X + Random.new():NextInteger(Min, Max) * Modifier, Part.Position.Y + Random.new():NextInteger(Min, Max) * Modifier, Part.Position.Z + Random.new():NextInteger(Min, Max) * Modifier)
local NewOrientaton = Vector3.new(Random.new():NextInteger(1, 360), Random.new():NextInteger(1, 360), Random.new():NextInteger(1, 360))
TweenService:Create(Part, tweenInfo, {
Position = NewPosition,
Orientation = NewOrientaton
}):Play()
else
Part:Destroy()
end
end
ServerStorage.OpenWall.Event:Connect(function()
for i, part in ipairs(workspace.WallCover:GetChildren()) do
WallCoverRandomPosTween(part, -7, 7, 1)
end
end)
it seems that vector3.new of a vector always gives back (0,0,0), which is probably why all your parts are amassing around one point (which should be the origin of the workspace)
math.random was always sometimes buggy with me because it uses a linear algorithm to get random numbers. Sometimes it would just repeat the same number over again, so you would have to use math.randomseed.
I’m fairly sure math.random’s backend now uses Random.new()'s but I still use Random.new() as it uses a non linear algorithm and it has more functions available.