My code dont work please help!

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I am making a tower defense game.
    Am currently working on tower placement but it doesn’t work…
    this is the whole “Tower” module script that is put in the “Main” script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")



function tower.Spawn(player ,name ,cframe)
	local towerExists = ReplicatedStorage.Towers:FindFirstChild(name)

	if towerExists then
		task.wait(0.5)
		local newTower = towerExists:Clone()
		newTower.HumanoidRootPart.CFrame = cframe
		newTower.Parent = workspace.Towers
		newTower.HumanoidRootPart:SetNetworkOwner(nil)

		for i, object in ipairs(newTower:GetDescendants()) do
			if object:IsA("BasePart") then
				object.CollisionGroup = "Tower"
			end
		end
	else
		warn("Requested tower dont exist", name)
	end
end

spawnTowerEvent.OnServerEvent:Connect(tower.Spawn())

return tower
  1. What is the issue?
    It throws this error:
    Argument 1 missing or nil (on line 12)
    And this one:
    Requested module experienced an error while loading

  2. What solutions have you tried so far?
    Looking at Youtube and Developer forum but nothing…

You should specify the name of the child on line 12

the name is currently “Slinger”

In that case, switch name for “Slinger”

Specify the script where you use this function.

You’re calling the function instead of passing it.

spawnTowerEvent.OnServerEvent:Connect(tower.Spawn)

okay the tower is here but I scripted that you can select his position and it throws this error:
Unable to assign property CFrame. CoordinateFrame expected, got nil

this somehow work but my tower is not placable

If the tower is not placeable, you will need to do the bug finding yourself.

That being said, I would check the new tower is actually being moved - frankly doing newTower:MoveTo(Position) is sufficient enough for moving entire models.

This line spawnTowerEvent.OnServerEvent:Connect(tower.Spawn()) is not giving any parameters.