please watch the video
As you can see I have a system where the player can pickup models and rotate them (not shown in video), it is in testing as of now but i want to put it into an actual game eventually.
However there are issues, picking up a modelwhile another is still held will cause the 2 to spin rapidly, also if you stand on a modeland then pick it up, when the game attempts to align the model to your character will get sent to low earth orbit. As I’m not good with roblox physics i would like to know what I can do to make everything work normally.
Server Code:
game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local partAttach = Instance.new("Attachment")
partAttach.Position = char:WaitForChild("Head"):WaitForChild("HatAttachment").Position - Vector3.new(0,0,5)
partAttach.Parent = char.Head
partAttach.Name = "HeadAttach"
local alignPos = Instance.new("AlignPosition")
alignPos.Parent = char:WaitForChild("Head")
alignPos.Name = "Allign"
alignPos.Mode = Enum.PositionAlignmentMode.TwoAttachment
alignPos.Responsiveness = math.huge
alignPos.MaxForce = math.huge
alignPos.MaxVelocity = math.huge
alignPos.RigidityEnabled = false
alignPos.ApplyAtCenterOfMass = true
end)
game.ReplicatedStorage:WaitForChild('Allign').OnServerEvent:Connect(function(player, allign , plrAttach , PartAttachment)
if allign ~= nil and plrAttach ~= nil and PartAttachment ~= nil then
player.Character.Humanoid.WalkSpeed = 0
print(player.Character.Humanoid.WalkSpeed)
allign.Attachment1 = plrAttach
allign.Attachment0 = PartAttachment
else
local allign = player.Character.Head.Allign :: AlignPosition
allign.Attachment0 = nil
player.Character.Humanoid.WalkSpeed = 16
end
end)
client:
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local plrAttach = char:WaitForChild("Head"):WaitForChild("HeadAttach")
local allign = char:WaitForChild("Head"):WaitForChild("Allign") :: AlignPosition
local mouse = player:GetMouse()
local DropButton = player.PlayerGui.Holding.Drop
local vert = 0
local hor = 0
local diag = 0
local recentlyEquip = false
local prevPart = nil ::Part
local save = {}
mouse.Button1Down:Connect(function()
local mouseTarget = mouse.Target
local PartAttachment = nil
local model = mouseTarget:FindFirstAncestorOfClass("Model")
local attachmentPart = nil :: Part
if model then
attachmentPart = model:FindFirstChild("Primary")
if attachmentPart then
PartAttachment = attachmentPart:FindFirstChild("Attachment")
end
end
if PartAttachment ~= nil then
attachmentPart.AssemblyAngularVelocity = Vector3.new(0,0,0)
recentlyEquip = true
task.delay(1, function()
recentlyEquip = false
end)
DropButton.Visible = true
game.ReplicatedStorage.Allign:FireServer(allign,plrAttach,PartAttachment)
end
end)
DropButton.MouseButton1Click:Connect(function()
DropButton.Visible = false
game.ReplicatedStorage.Allign:FireServer(allign)
end)
UIS.InputBegan:Connect(function(input, gp)
if input.KeyCode == Enum.KeyCode.W then
vert += 10
end
if input.KeyCode == Enum.KeyCode.S then
vert -= 10
end
if input.KeyCode == Enum.KeyCode.D then
hor += 10
end
if input.KeyCode == Enum.KeyCode.A then
hor -= 10
end
if input.KeyCode == Enum.KeyCode.E then
diag += 10
end
if input.KeyCode == Enum.KeyCode.Q then
diag -= 10
end
end)
UIS.InputEnded:Connect(function(input, gp)
if input.KeyCode == Enum.KeyCode.W then
vert -= 10
end
if input.KeyCode == Enum.KeyCode.S then
vert += 10
end
if input.KeyCode == Enum.KeyCode.D then
hor -= 10
end
if input.KeyCode == Enum.KeyCode.A then
hor += 10
end
if input.KeyCode == Enum.KeyCode.E then
diag -= 10
end
if input.KeyCode == Enum.KeyCode.Q then
diag += 10
end
end)
while task.wait(0.01) do
if recentlyEquip == false then
if allign.Attachment0 then
local targetPart = allign.Attachment0.Parent :: Part
if targetPart then
targetPart.CFrame = targetPart.CFrame * CFrame.Angles(math.rad(vert), math.rad(hor), math.rad(diag))
end
end
end
end