Weird behaviour from align position

Hello, I’ve been encountering these very weird behaviour’s from align-position.

Such as:

  • part sinking to the ground
  • inconsistent speed

Video and Code:

https://cdn.discordapp.com/attachments/1220554132885213264/1222082748156477481/2024-03-26_15-19-07.mp4?ex=6614ec40&is=66027740&hm=62d64fa77f5b8f676d7f88809da9c320d251e556e62978839e3091be1e4b6830&

--// Services

local Replicated = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local MarketPlaceService = game:GetService("MarketplaceService")
local Debris = game:GetService("Debris")
local tween = game:GetService("TweenService")

--// Vars

local AbilityFolder = Replicated:WaitForChild("Abilities")
local AbilityList = require(AbilityFolder.AbilityList)

local Remotes = Replicated.Remotes

local alignOrientationTemplate = Instance.new("AlignOrientation")
alignOrientationTemplate.RigidityEnabled = true

function changePlayerSize(plr, cube, isclonecube)
	
	local minSize = 2.5
	local maxPlayerSize = 25
	
	if isclonecube then
		local char = cube.Parent
		if not char then return end
		
		local newSize = math.clamp(cube:GetAttribute("Size")/128, 0, 50)

		if newSize<25 then
			newSize += minSize
		end

		local legSize = (newSize/4)*2	
		char["Left Leg"].Size = Vector3.new(1,legSize,1)
		char["Right Leg"].Size = Vector3.new(1,legSize,1)
		char.Cube.Size = Vector3.new(newSize,newSize,newSize)
		char.Cube.Size = Vector3.new(newSize/1.01,newSize/1.01,newSize/1.01)
	else

		local char = plr.Character
		
		local newSize = math.clamp(plr.leaderstats.Size.Value/128, 0, 50)
		
		if not char then return end

		if newSize<25 then
			newSize += minSize
		end

		local legSize = (newSize/4)*2	
		char["Left Leg"].Size = Vector3.new(1,legSize,1)
		char["Right Leg"].Size = Vector3.new(1,legSize,1)
		char.Cube.Size = Vector3.new(newSize,newSize,newSize)
		char.Cube.Size = Vector3.new(newSize/1.01,newSize/1.01,newSize/1.01)

		local size = plr.leaderstats.Size.Value

		if char.Humanoid.WalkSpeed > 36 then
			print("Got fast walkspeed, not doing anything to speed.")
		else
			print("Changing walkspeed.")
			if size > 1_000_000 then
				char.Humanoid.WalkSpeed *= .95
			elseif size > 250_000 then
				char.Humanoid.WalkSpeed *= .96
			elseif size > 100_000 then
				char.Humanoid.WalkSpeed *= .97
			elseif size > 50_000 then
				char.Humanoid.WalkSpeed *= .98
			elseif size > 10_000 then
				char.Humanoid.WalkSpeed *= .99
			elseif size > 1_000 then
				char.Humanoid.WalkSpeed = 29
			else
				warn(size)
			end
		end
	end
end

function cubeEat(cube, plr)

	cube.Touched:Connect(function(hit)
		local otherPlr = game.Players:GetPlayerFromCharacter(hit.Parent)

		if otherPlr ~= plr and otherPlr ~= nil then
			
			if otherPlr.leaderstats.Size.Value < plr.leaderstats.Size.Value and otherPlr.Character.Humanoid.Health > 0 then
				
				plr.leaderstats.Kills.Value += 1
				
				if MarketPlaceService:UserOwnsGamePassAsync(plr.UserId,game.ReplicatedStorage.IDs.GamepassIDs['2x Kills'].Value) then
					plr.leaderstats.Kills.Value += 1
				end
				
				otherPlr.MainData.SizeBeforeDeath.Value = otherPlr.leaderstats.Size.Value
				otherPlr.Character.Humanoid.Health = 0
				
				Remotes.KilledBy:FireClient(otherPlr,plr.Name)
				otherPlr.MainData.LastKiller.Value = plr
				
				cube:SetAttribute("Size", cube:GetAttribute("Size")+otherPlr.leaderstats.Size.Value)
				
			end
		end
	end)
end

return function(player : Player)
	
	player.leaderstats.Size.Value = player.leaderstats.Size.Value / 2
	changePlayerSize(player, nil, false)
	
	local character = player.Character or player.CharacterAdded:Wait()
	local CharacterCube : Part = character:WaitForChild("Cube")
	
	character.Archivable = true
	
	local ClonedCharacter : Model = character:Clone()
	ClonedCharacter.Name = player.Name
	
	ClonedCharacter:PivotTo(CharacterCube.CFrame * CFrame.new(0, 0, -20))
	ClonedCharacter.Parent = workspace.AbilityObjects
	
	local ClonedCube : Part = ClonedCharacter.Cube
	local ClonedCubeHuman : Humanoid = ClonedCharacter.Humanoid
	
	ClonedCube:SetAttribute("Size", player.leaderstats.Size.Value)
	
	local clonegui : BillboardGui = ClonedCube.BillboardGui
	
	ClonedCube:GetAttributeChangedSignal("Size"):Connect(function()
		changePlayerSize(player, ClonedCube, true)
		clonegui.StudsOffset = Vector3.new(0,ClonedCube:GetAttribute("Size")/32+3,0)
		clonegui.Health.Text = "Size: "..ClonedCube:GetAttribute("Size")
	end)
	
	character.Archivable = false
	
	local charOriAttachment = Instance.new("Attachment", CharacterCube)
	local cloneOriAttachment = Instance.new("Attachment", ClonedCube)
	
	local posatt = Instance.new('Attachment', CharacterCube)
	local cloneattpos = Instance.new("Attachment", ClonedCube)
	
	posatt.Position = Vector3.new(0, 0, -70)
	
	local alignOrientation = alignOrientationTemplate:Clone()
	alignOrientation.Attachment0 = cloneOriAttachment
	alignOrientation.Attachment1 = charOriAttachment
	alignOrientation.Parent = CharacterCube
	
	local mover = Instance.new('AlignPosition', ClonedCube)
	mover.Attachment0 = cloneattpos
	mover.Attachment1 = posatt
	mover.RigidityEnabled = true
	
	tween:Create(posatt, TweenInfo.new(3), {Position = ClonedCube.CFrame:ToObjectSpace(CharacterCube.CFrame).Position}):Play()
	
	cubeEat(ClonedCube, player)
	
	-- END ABILITY
	
	task.wait(20)
	
	player.leaderstats.Size.Value += ClonedCube:GetAttribute("Size")
	changePlayerSize(player, nil, false)
	
	ClonedCharacter:Destroy()
	
end

How do I fix? I have a deadline on Monday.

1 Like
--// Services

local Replicated = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local MarketPlaceService = game:GetService("MarketplaceService")
local Debris = game:GetService("Debris")
local tween = game:GetService("TweenService")

--// Vars

local AbilityFolder = Replicated:WaitForChild("Abilities")
local AbilityList = require(AbilityFolder.AbilityList)

local Remotes = Replicated.Remotes

local alignOrientationTemplate = Instance.new("AlignOrientation")
alignOrientationTemplate.RigidityEnabled = true

function changePlayerSize(plr, cube, isclonecube)
	
	local minSize = 2.5
	local maxPlayerSize = 25
	
	if isclonecube then
		local char = cube.Parent
		if not char then return end
		
		local newSize = math.clamp(cube:GetAttribute("Size")/128, 0, 50)

		if newSize<25 then
			newSize += minSize
		end

		local legSize = (newSize/4)*2	
		char["Left Leg"].Size = Vector3.new(1,legSize,1)
		char["Right Leg"].Size = Vector3.new(1,legSize,1)
		char.Cube.Size = Vector3.new(newSize,newSize,newSize)
		char.Cube.Size = Vector3.new(newSize/1.01,newSize/1.01,newSize/1.01)
	else

		local char = plr.Character
		
		local newSize = math.clamp(plr.leaderstats.Size.Value/128, 0, 50)
		
		if not char then return end

		if newSize<25 then
			newSize += minSize
		end

		local legSize = (newSize/4)*2	
		char["Left Leg"].Size = Vector3.new(1,legSize,1)
		char["Right Leg"].Size = Vector3.new(1,legSize,1)
		char.Cube.Size = Vector3.new(newSize,newSize,newSize)
		char.Cube.Size = Vector3.new(newSize/1.01,newSize/1.01,newSize/1.01)

		local size = plr.leaderstats.Size.Value

		if char.Humanoid.WalkSpeed > 36 then
			print("Got fast walkspeed, not doing anything to speed.")
		else
			print("Changing walkspeed.")
			if size > 1_000_000 then
				char.Humanoid.WalkSpeed *= .95
			elseif size > 250_000 then
				char.Humanoid.WalkSpeed *= .96
			elseif size > 100_000 then
				char.Humanoid.WalkSpeed *= .97
			elseif size > 50_000 then
				char.Humanoid.WalkSpeed *= .98
			elseif size > 10_000 then
				char.Humanoid.WalkSpeed *= .99
			elseif size > 1_000 then
				char.Humanoid.WalkSpeed = 29
			else
				warn(size)
			end
		end
	end
end

function cubeEat(cube, plr)

	cube.Touched:Connect(function(hit)
		local otherPlr = game.Players:GetPlayerFromCharacter(hit.Parent)

		if otherPlr ~= plr and otherPlr ~= nil then
			
			if otherPlr.leaderstats.Size.Value < plr.leaderstats.Size.Value and otherPlr.Character.Humanoid.Health > 0 then
				
				plr.leaderstats.Kills.Value += 1
				
				if MarketPlaceService:UserOwnsGamePassAsync(plr.UserId,game.ReplicatedStorage.IDs.GamepassIDs['2x Kills'].Value) then
					plr.leaderstats.Kills.Value += 1
				end
				
				otherPlr.MainData.SizeBeforeDeath.Value = otherPlr.leaderstats.Size.Value
				otherPlr.Character.Humanoid.Health = 0
				
				Remotes.KilledBy:FireClient(otherPlr,plr.Name)
				otherPlr.MainData.LastKiller.Value = plr
				
				cube:SetAttribute("Size", cube:GetAttribute("Size")+otherPlr.leaderstats.Size.Value)
				
			end
		end
	end)
end

return function(player : Player)
	
	player.leaderstats.Size.Value = player.leaderstats.Size.Value / 2
	changePlayerSize(player, nil, false)
	
	local character = player.Character or player.CharacterAdded:Wait()
	local CharacterCube : Part = character:WaitForChild("Cube")
	
	character.Archivable = true
	
	local ClonedCharacter : Model = character:Clone()
	ClonedCharacter.Name = player.Name
	
	ClonedCharacter:PivotTo(CharacterCube.CFrame * CFrame.new(0, 0, -20))
	ClonedCharacter.Parent = workspace.AbilityObjects
	
	local ClonedCube : Part = ClonedCharacter.Cube
	local ClonedCubeHuman : Humanoid = ClonedCharacter.Humanoid
	
	ClonedCube:SetAttribute("Size", player.leaderstats.Size.Value)
	
	local clonegui : BillboardGui = ClonedCube.BillboardGui
	
	ClonedCube:GetAttributeChangedSignal("Size"):Connect(function()
		changePlayerSize(player, ClonedCube, true)
		clonegui.StudsOffset = Vector3.new(0,ClonedCube:GetAttribute("Size")/32+3,0)
		clonegui.Health.Text = "Size: "..ClonedCube:GetAttribute("Size")
	end)
	
	character.Archivable = false
	
	local charOriAttachment = Instance.new("Attachment", CharacterCube)
	local cloneOriAttachment = Instance.new("Attachment", ClonedCube)
	
	local posatt = Instance.new('Attachment', CharacterCube)
	local cloneattpos = Instance.new("Attachment", ClonedCube)
	
	posatt.Position = Vector3.new(0, 0, -100)
	
	local alignOrientation = alignOrientationTemplate:Clone()
	alignOrientation.Attachment0 = cloneOriAttachment
	alignOrientation.Attachment1 = charOriAttachment
	alignOrientation.Parent = CharacterCube
	
	local mover = Instance.new('AlignPosition', ClonedCube)
	mover.Attachment0 = cloneattpos
	mover.Attachment1 = posatt
	
	mover.RigidityEnabled = true
	
	cubeEat(ClonedCube, player)
	
	task.wait(0.85)
	mover:Destroy()
	
	RunService.Stepped:Connect(function()
		ClonedCube.Velocity = (CharacterCube.Velocity) * 1.35
	end)
	
	-- END ABILITY
	
	task.wait(20)
	
	player.leaderstats.Size.Value += ClonedCube:GetAttribute("Size")
	changePlayerSize(player, nil, false)
	
	ClonedCharacter:Destroy()
	
end

Fixed it by myself, heres code above:

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