Chest keeps spawning halfway inside ground

What do you want to achieve? I’m making a tool that whenever you click, It will spawn a chest at that location and face the player.

What is the issue? The chest spawns halfway inside the ground

LocalScript:

local tool = script.Parent
local handle = tool.Handle

local UIS = game:GetService("UserInputService")
local spawnWeaponRe = tool:WaitForChild("spawnWeapon")

local chest = game.ReplicatedStorage.Chest
local camera = workspace.CurrentCamera

tool.Activated:Connect(function()
	local plr = game.Players.LocalPlayer
	local humanoid = plr.Character.HumanoidRootPart

	if humanoid then
		local mouse = UIS:GetMouseLocation()
		local mouseRay = camera:ViewportPointToRay(mouse.X, mouse.Y)

		local raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000)
		local origin = mouseRay.Origin
		
		if raycastResult then
			spawnWeaponRe:FireServer(raycastResult.Position)
		end
	end
end)

script:

local tool = script.Parent
local spawnWeaponRe = tool.spawnWeapon
local weapons = game.ReplicatedStorage.WeaponStorage

spawnWeaponRe.OnServerEvent:Connect(function(plr, position)
	local clonedChest = game.ReplicatedStorage.Chest:Clone()
	clonedChest.Parent = workspace.Map
	
	local char = plr.Character
	local plrPos = char.HumanoidRootPart.Position

	clonedChest:PivotTo(CFrame.lookAt(position, plrPos))
	
	for i, weapon in ipairs(weapons:GetChildren()) do
		if not weapon:IsA("Tool") then
			continue
		end
		
		local clone = weapon:Clone()
		clone.Parent = clonedChest.BottomBox
		clone.Handle.CFrame = clonedChest.SpawnItemsLoc.CFrame
	end
	
end)

Anyway to make the chest spawn on top of the ground?.

2 Likes

Try adding half of the chest’s height to the Y value of the position within CFrame when spawning it in.

3 Likes

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