My placement system is broken! (Can't place anywhere?)

Old problem has been solved, but a new problem has been found:

I decided to do some proper debugging and research to fix my old problem (Old version of post) and I found out this:

  1. Doing some printing, I found out that for some reason baseplate turns to nil after some time.

Current code (Server):

remotes.isPlacingEvent.OnServerEvent:Connect(function(plr, x, z, y, mouseOrigin)
		local blackList = {}
		local tower = toPlace:GetChildren()
		local primaryPart
		for i, part in ipairs(tower) do
			if part.Name == "Tower" or part.Parent.PrimaryPart == part then primaryPart = part end
			table.insert(blackList, part)
		end
		for i, v in ipairs(game.Players:GetPlayers()) do
			local char = v.Character or v.CharacterAdded:Wait()
			for j, part in ipairs(char:GetChildren()) do
				if part:IsA("BasePart") then
					table.insert(blackList, part)
				end
			end
		end
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = blackList
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		raycastParams.IgnoreWater = true
		local rayCast2 = game.Workspace:Raycast(mouseOrigin, Vector3.new(0, -10, 0), raycastParams)
		local raycastResult2
		if rayCast2 ~= nil then
			print(rayCast2)
			raycastResult2 = rayCast2.Instance
		elseif rayCast2 == nil then
			raycastResult2 = game.ServerStorage.BaseplateCopy
		end
		
		if raycastResult2.Parent == game.Workspace.AllowedToPlaceOn then
			for i, part in ipairs(toPlace:GetChildren()) do
				if hasProperty(part, "UsePartColor") then
					part.UsePartColor = false
				elseif hasProperty(part, "BrickColor") then
					part.BrickColor = rangeColor
				else
					continue
				end
			end
			ableToPlace = true
			remotes.SendPlacementStatus:FireClient(plr, ableToPlace)
		else
			print(raycastResult2)
			for i, part in ipairs(toPlace:GetChildren()) do
				if hasProperty(part, "UsePartColor") then
					part.UsePartColor = true
				elseif hasProperty(part, "BrickColor") then
					part.BrickColor = BrickColor.new("Really red")
				else
					continue
				end
			end
			print("You are not allowed to place here")
			ableToPlace = false
			remotes.SendPlacementStatus:FireClient(plr, ableToPlace)
		end
		placeFunction(toPlace, x, z, raycastResult2, y)
	end)

Local Script (Everything):

local repStorage = game:GetService("ReplicatedStorage")
local remotes = require(repStorage:WaitForChild("RemoteModule"))
local runService = game:GetService("RunService")
local isPlacing = false
local UserInputService = game:GetService("UserInputService")
local plrService = game:GetService("Players")
local PlaceConnection
local RotateConnection
local currentTowerBeingPlaced = nil
local plr = plrService.LocalPlayer
local rotateDebounce = false
local tweenService = game:GetService("TweenService")
local ableToPlace
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quint, Enum.EasingDirection.Out, 0, false)
script.Parent.MouseButton1Up:Connect(function()
	remotes.SendPlacementStatus.OnClientEvent:Connect(function(status)
		ableToPlace = status
	end)
	print("Clicked!")
	print(isPlacing)
	if isPlacing == false then
		isPlacing = true
		local mouse = plr:GetMouse()
		local tower = repStorage:WaitForChild(script.Parent.Name)
		remotes.startPlacing:FireServer(tower)
		remotes.SendTower.OnClientEvent:Connect(function(towerE)
			mouse.TargetFilter = towerE
			currentTowerBeingPlaced = towerE
			print(currentTowerBeingPlaced)
		end)
		print("Fired from client!")
		PlaceConnection = runService.RenderStepped:Connect(function()
			remotes.isPlacingEvent:FireServer(mouse.Hit.Position.X, mouse.Hit.Position.Z, mouse.Hit.Position.Y, mouse.UnitRay.Origin)
		end)
		remotes.SetTransparencyToOtherClients.OnClientEvent:Connect(function(transparency, towerE)
			for i, part in ipairs(towerE:GetChildren()) do
				part.Transparency = transparency
			end
		end)
		RotateConnection = UserInputService.InputBegan:Connect(function(input, gpu)
			if gpu then return end
			if input.KeyCode == Enum.KeyCode.R then
				if not rotateDebounce then
					rotateDebounce = true
					print(currentTowerBeingPlaced)
					remotes.RotateOnServer:FireServer()
					local tween = tweenService:Create(currentTowerBeingPlaced.PrimaryPart, tweenInfo, {Orientation = currentTowerBeingPlaced.PrimaryPart.Orientation + Vector3.new(0, 90, 0)})
					tween:Play()
					tween.Completed:Wait()
					rotateDebounce = false
				end
			end
		end)
		local downConnection = mouse.Button1Down:Connect(function()
			if ableToPlace then
				remotes.place:FireServer()
				RotateConnection:Disconnect()
				PlaceConnection:Disconnect()
				isPlacing = false
			else
				print("Cannot place tower")
			end
		end)
	end
end)

Please ignore the fact that I have to use 7 remote events. If you find anything else wrong please tell me :slight_smile: Thank you!

How many posts are you gonna make about this, just use mouse.hit.p for positions

Just make one post and if issue still persists post it in the old posts

I am literally doing that right now, and the old version of this post is this post which had a different problem, which was fixed. This problem is also fixed right now.