Issue with AlignPosition, items clip through ground when I release my mouse button

Anyone know why it clips through the ground when I drop it?
It should just get released where it is when I stop holding down my mouse button

local function press(input, gpa)
	if gpa then return end
	if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
	if renderSteppedConnection ~= nil then return end
	
	local hovering, instance = hoveringOverItem()
	if hovering and not instance:FindFirstChild('CarriedBy') and (instance.Parent == items or instance.Parent.Name == 'Plate' or instance.Parent:FindFirstChild('Attachment')) then
		carryControls.Visible = true
		doorControls.Visible = false
		grillProgress.Visible = false
		
		carrying = instance
		
		alignPosition = script.AlignPosition:Clone()
		alignPosition.Attachment0 = carrying:FindFirstChild('Attachment')
		alignPosition.Parent = carrying
		
		alignOrientation = script.AlignOrientation:Clone()
		alignOrientation.Attachment0 = carrying:FindFirstChild('Attachment')
		alignOrientation.Parent = carrying
		
		highlight = Instance.new('Highlight')
		highlight.FillTransparency = 1
		highlight.OutlineColor = Color3.new(0, 0, 0)
		highlight.OutlineTransparency = 0
		highlight.Adornee = carrying
		highlight.DepthMode = Enum.HighlightDepthMode.Occluded
		highlight.Parent = carrying
		
		-- carrying.CanCollide = false
		
		carryRemote:FireServer(instance)
		renderSteppedConnection = game:GetService('RunService').RenderStepped:Connect(function()
			alignPosition.Position = raycast()
			alignOrientation.CFrame *= CFrame.Angles(math.rad(vertical*5), math.rad(horizontal*5), 0)
		end)
		
		if renderSteppedDoorConnection ~= nil then
			renderSteppedDoorConnection:Disconnect()
			renderSteppedDoorConnection = nil
		end
		if renderSteppedProgressConnection ~= nil then
			renderSteppedProgressConnection:Disconnect()
			renderSteppedProgressConnection = nil
		end
	end
end

local function release(input, gpa)
	if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
	if renderSteppedConnection ~= nil then renderSteppedConnection:Disconnect() renderSteppedConnection = nil end
	if carrying ~= nil then
		carryRemote:FireServer(carrying)
		carrying = nil
		
		alignPosition:Destroy()
		alignPosition = nil
		
		alignOrientation:Destroy()
		alignOrientation = nil
		
		highlight:Destroy()
		highlight = nil
		
		-- carrying.CanCollide = true
		
		carryControls.Visible = false
		
		renderSteppedDoorConnection = game:GetService('RunService').RenderStepped:Connect(doorInView)
		renderSteppedProgressConnection = game:GetService('RunService').RenderStepped:Connect(grillableInView)
	end
end





UserInputService.InputBegan:Connect(press)
UserInputService.InputEnded:Connect(release)

Server

local items = workspace.Items

for _, item in items:GetChildren() do
	item:SetNetworkOwner(nil)
end




local carryRemote = game.ReplicatedStorage.Carry

carryRemote.OnServerEvent:Connect(function(player: Player, part: BasePart)
	if not part:FindFirstChild('CarriedBy') then
		local tag = Instance.new('ObjectValue')
		tag.Value = player
		tag.Name = 'CarriedBy'
		tag.Parent = part
		
		part:SetNetworkOwner(player)
		part.CanCollide = false
	elseif part:FindFirstChild('CarriedBy').Value == player then
		part:FindFirstChild('CarriedBy'):Destroy()
		part:SetNetworkOwner(nil)
		part.CanCollide = true
	end
end)
1 Like

Maybe this can help.

1 Like
carryRemote:FireServer(instance)
		renderSteppedConnection = game:GetService('RunService').RenderStepped:Connect(function()
			local position, normal = raycast()
			alignOrientation.CFrame *= CFrame.Angles(math.rad(vertical*5), math.rad(horizontal*5), 0)
			if normal then
				alignPosition.Position = position + (normal * (instance.Size / 2))
			else
				alignPosition.Position = position
			end
		end)
```I tried that but weird results
![Untitled Game - Roblox Studio 2023-08-08 00-47-48|video](upload://jR9MkPukaaMCXQaRcv0ZF1nfJTu.mp4)

Oh nvm it worked! It was a problem with my union rather than the script

1 Like

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