My placement isn't being shown in the right place!

Hello, recently I’ve been making a TD game and I’m having a problem where my keeps moving up when I try to place it.

Video:

Server Code:

function self.Spawn(player, name, cframe)
	local Exist = ServerStorage.Humanoids.Towers:FindFirstChild(name):FindFirstChild(name.."_Level_1")
	local TowerData = _G.GetModule("TowerData")[name].Level_1
	if Exist and _G.GetProfile(player).Data.Cash > TowerData.Cost then

		local NewTower = Exist:Clone()
		NewTower.HumanoidRootPart.CFrame = cframe
		
		_G.SetGroupModel(NewTower, "Tower")
		NewTower.Parent = workspace.Towers
		
		
		local bodyGyro = Instance.new("BodyGyro")
		bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
		bodyGyro.D = 0
		bodyGyro.CFrame = NewTower:WaitForChild("HumanoidRootPart").CFrame
		bodyGyro.Parent = NewTower.HumanoidRootPart
		
		task.spawn(self.Attack(NewTower, TowerData))
		
	else
		_G.Error("Tower "..name.." does not exist!")
	end

end

Client Side Code:

return function()
	
	local UIS = game:GetService("UserInputService")
	
	local Tower
	
	local canPlace = false
	local rotation = 0
	
	local RS = game:GetService("ReplicatedStorage")
	
	local Remotes = RS.Events
	local PlaceRemote = Remotes.PlaceTower
	
	local TOWERS_FOLDER = RS:WaitForChild("TOWERS")	
	
	function _G.DeletePlaceholder()
		if Tower then
			Tower:Destroy()
			Tower = nil
		end
		rotation = 0
	end
	
	function _G.ShowPlaceholder(Name)
		local towerExist = TOWERS_FOLDER:FindFirstChild(Name)
		
		if towerExist then
			_G.DeletePlaceholder()
			Tower = towerExist:Clone()
			Tower.Parent = workspace.MouseFilter
			_G.SetGroupModel(Tower, "Tower")
		end
		
	end
	
	local function ColorPlaceholder(color)
		for _, part in pairs(Tower:GetDescendants()) do
			if part:IsA("BasePart") then
				part.Color = color
				part.CanQuery = false
			end
		end
	end
	
	local UI = _G.Player:WaitForChild("PlayerGui"):WaitForChild("TowerPlacement"):WaitForChild("PlacementFrame")
	
	UIS.InputBegan:Connect(function(input, processed)
		if processed then
			return
		end
		if Tower then
			if input.UserInputType == Enum.UserInputType.MouseButton1 then
				if canPlace then
					PlaceRemote:FireServer(Tower.Name, Tower.PrimaryPart.CFrame)
					_G.DeletePlaceholder()
				end
			elseif input.KeyCode == Enum.KeyCode.R then
				rotation += 90
			end
		end
	end)
	
	game:GetService("RunService").RenderStepped:Connect(function()
		if Tower then
			local result = _G.MouseRay({Tower})
			if result and result.Instance then
				if result.Instance.Parent.Name == "TowerArea" then
					canPlace = true
					ColorPlaceholder(Color3.new(0, 1, 0))
				else
					ColorPlaceholder(Color3.new(1, 0, 0))
					canPlace = false
				end
				local x = result.Position.X
				local y = result.Position.Y + Tower.Humanoid.HipHeight + (Tower.PrimaryPart.Size.Y / 2)
				local z = result.Position.Z
					
				local cframe = CFrame.new(x, y, z) * CFrame.Angles(0, math.rad(rotation), 0)
		
				Tower:SetPrimaryPartCFrame(cframe)
			end
		end
	end)
end

Thank you!

+ Tower.Humanoid.HipHeight One question this is a part of the Hover effect right?

That is to make sure that the tower Placeholder doesn’t have the HumanoidRootPart Clipping in the ground

Yes I see now look in your tower and go to its Humanoid Hipheight and check if its to High.

It isn’t, if you look at the video it shows that the placeholder is in the correct place

Ik that it’s in the right place but based on the Bounce the Tower gives it shows its Hipheight could potentially be to High.

I made sure the hipheight was equal to the length of the right leg.

Yes that may be ur issue try the length of the Right leg Divided by 2 and see what Happens?

It does the same thing, but it lowers he placeholder

You are defining the PrimaryPart.CFrame already, so you don’t have to add the +HipHeight.
Aka in client, you are having it at perfect position,
then you are firing the humanoidrootposition instead of the mousehitposition,
which basically means you don’t need the +hipheigt :slight_smile:

but its better to use a raycast using +vector3.new(0,5,0) and then making the raycast go down to vector3.new(0,-10,0) and if it hits something checking part then u can place.
then add a box around the thing, checking if position is inside area, by that you stop overlapping.

The + Hipheight is for the Placeholder { aka the green / red part } othewrwise it would sink into the ground

Can u send a picture of the Humanoids Hipheight in ur tower?

image

size of the leg
image

Now while the game is running try adjusting its hipheight on the server and see if the Floating is fixed.

1 Like