Why do I always get the same resault with this tween?

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)

Does anyone know why this is happening?

Can you send a picture? İ cant open the video cause i am in mobile

Try this:

--//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)
1 Like

how does this even work?? you are doing Vector3.new(Vector3)

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

1 Like

Thank you, I’m such an idiot. I must have accedently typed Vector3.New() twice.

1 Like

Whats the diffrence between Math.Random() and Random.New():NextInteger()?

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.

It’s mostly up to personal choice though.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.