Remote event error

pretty sure this is the 80th time ive gotten an error while making my tds game

So basically, im trying to pass the tower being placed through a remote event to see what tower to clone.

but im getting an error:
image

here is the client sided code:

local player = game.Players.LocalPlayer
local Character = player.Character
local HRP = player.Character:WaitForChild("HumanoidRootPart")

local Mouse = player:GetMouse()

local renderingPath
local placingPath

local canPlace = false
local isPlacing = false

local rendering = game:GetService("RunService")
local Towers_ = script.Parent.InventoryBar:GetChildren()


for _, towerPicked in pairs(Towers_) do
	towerPicked.MouseButton1Click:Connect(function()
		
		local clientTowerPreview = towerPicked.Tower:Clone()
		clientTowerPreview.Parent = workspace
		Mouse.TargetFilter = clientTowerPreview
	
		renderingPath = rendering.RenderStepped:Connect(function()
			clientTowerPreview.LeftFoot.CFrame = CFrame.new(Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z)
		end)
		
		placingPath = game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
			if not gameProcessed then
				if input.UserInputType == Enum.UserInputType.MouseButton1 and canPlace == true then
					
					local CurrPos_ = clientTowerPreview.HumanoidRootPart.CFrame
					
					renderingPath:Disconnect()
					placingPath:Disconnect()
					clientTowerPreview:Destroy()
					
					game.ReplicatedStorage.TowerPlaced:FireServer(CurrPos_, clientTowerPreview)
					
				elseif canPlace == false then return 
										
				end
			end
		end)
	end)
end

server code:

game.ReplicatedStorage.TowerPlaced.OnServerEvent:Connect(function(player, CurrPos_, clientTowerPreview)
	
	local finalTowerPlaced_ = game.ReplicatedStorage.Tower:Clone()
	finalTowerPlaced_.HumanoidRootPart.CFrame = CurrPos_
	finalTowerPlaced_.Parent = workspace
	
	print(clientTowerPreview.HumanoidRootPart.Position) --Gives an erroor
	
end)

Thanks in advance

clientTowerPreview only exists on the client, since it is created on the client, which is why it is nil on the server.

So I cant pass it on to the server?

clientTowerPreview:Destroy()

You’re destroying the clientTowerPreview object before attempting to send it to the server.

1 Like

Oh thats why, thanks a lot

character696696