Model gets stuck under map

  1. What do you want to achieve?
    For the model to be on top of the map properly

  2. What is the issue?
    It gets stuck under the map for some reason

  3. What solutions have you tried so far?
    I tried chaning up the Y value, but it didn’t help

RunService.RenderStepped:Connect(function()
	if TowerToSpawn then
		local result = MouseRaycast({TowerToSpawn})
		if result and result.Instance then
			local GetRangeBoxTouchingParts = TowerToSpawn.RangeBox:GetTouchingParts()

			if result.Instance.Parent.Name == "TowerArea" or result.Instance:GetAttribute("TowerPlaceArea") == true then
				CanPlace = true
				ColorPlaceholderTower(Color3.new(0,1,0))
			else
				CanPlace = false
				ColorPlaceholderTower(Color3.new(1,0,0))
			end

			for index, part in ipairs(GetRangeBoxTouchingParts) do
				if part.Name == "RangeBox" and part.Parent ~= TowerToSpawn then
					CanPlace = false
					ColorPlaceholderTower(Color3.new(1,0,0))
				end
			end

			local x = result.Position.X
			local y 
			if TowerToSpawn.Humanoid.RigType == Enum.RigType.R15 then
				print("R15")
				y = result.Position.Y + TowerToSpawn.Humanoid.HipHeight + (TowerToSpawn.PrimaryPart.Size.Y / 2)
			else
				print("R6")
				y = TowerToSpawn:GetExtentsSize().Y / 2
			end
			local z = result.Position.Z


			local cframe = CFrame.new(x,y,z) * CFrame.Angles(0, math.rad(Rotation), 0)
			TowerToSpawn:SetPrimaryPartCFrame(cframe)
			PhysicsService:SetPartCollisionGroup(TowerToSpawn.Range,"Tower")
			PhysicsService:SetPartCollisionGroup(TowerToSpawn.RangeBox,"TowerBox")
			TowerToSpawn.Range.Size = Vector3.new(0.1, TowerToSpawn.Levels[TowerToSpawn.CurrentLevel.Value].Range.Value * 2, TowerToSpawn.Levels[TowerToSpawn.CurrentLevel.Value].Range.Value * 2)
		end
	end
end)

I believe you are missing the result y position for the R6 scenario, it also would make sense as the y value is the one having issues as the model is under the map but the XZ seem ok.

			if TowerToSpawn.Humanoid.RigType == Enum.RigType.R15 then
				print("R15")
				y = result.Position.Y + TowerToSpawn.Humanoid.HipHeight + (TowerToSpawn.PrimaryPart.Size.Y / 2)
			else
				print("R6")
				y = result.Position.Y + TowerToSpawn:GetExtentsSize().Y / 2
			end

1 Like

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