Argument 1 missing or nil

Hey this is part 2 of my last post since no one responded so I posted another post

Soo the error was located in Line 11 in this script:

Signal Retriever

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicatedStorage:WaitForChild("Remote")
local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")
local TowerInfoEvent = Remotes:WaitForChild("TowerInfo")
local TowersFolder = ReplicatedStorage:WaitForChild("Towers")

local SignalEvent = script.Parent.Signal

SignalEvent.OnServerEvent:Connect(function(Player, TowerName)
	local ConfirmedTowers = TowersFolder:FindFirstChild(TowerName)
	
	print(ConfirmedTowers)
	
	TowerInfoEvent:FireClient(Player, ConfirmedTowers.Name)
end)

The signal retriever receives information from this script:

Signal Sender

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicatedStorage:WaitForChild("Remote")
local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")
local TowerInfoEvent = Remotes:WaitForChild("TowerInfo")
local TowersFolder = ReplicatedStorage:WaitForChild("Towers")

local SignalEvent = script.Parent.Signal

script.Parent.Activated:Connect(function(Player)
	SignalEvent:FireServer(Player, "Outrider")
end)

When you are calling FireServer:() you don’t need to put player in the arguments as it’s automatically a parameter when called by .OnServerEvent. This results in TowerName being the player object which will return nil.

SignalEvent:FireServer("Outrider")
4 Likes

Instead of sending ConfirmedTowers.Name

Do

local ConfirmedTowersName = ConfirmedTowers.Name

remote:FireClient(player, ConfirmedTowersName)

Also in the FireServer thing do the same for string, e.g. put string in the variable

Alright, thanks both of you but my placement system still doesn’t work, I need your help

Since I don’t know how to make a Placement system I watched GnomeCode’s tutorial I customized the system a little bit

Also, I got a new error after I used Primitived’s code

(I’m so sorry if I wasted everybody’s time)

System (Main Script) (Local Script)

local PhysicsEngine = game:GetService("PhysicsService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local Remotes = ReplicatedStorage:WaitForChild("Remote")
local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")
local TowerInfoEvent = Remotes:WaitForChild("TowerInfo")
local TowersFolder = ReplicatedStorage:WaitForChild("Towers")
local Camera = workspace.CurrentCamera
local Gui = script.Parent

local TowerToSpawn = nil
local CanPlace = false
local Rotation = 0

local function MouseRaycast(Blacklist)
	local MousePos = UserInputService:GetMouseLocation()
	local Mouseray = Camera:ViewportPointToRay(MousePos.X, MousePos.Y)
	local Raycastparams = RaycastParams.new()

	Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
	Raycastparams.FilterDescendantsInstances = Blacklist

	local RaycastResult = workspace:Raycast(Mouseray.Origin, Mouseray.Direction * 1000, Raycastparams)

	return RaycastResult
end

local function RemovePlaceholder()
	if TowerToSpawn then
		TowerToSpawn:Destroy()
		TowerToSpawn = nil
		Rotation = 0
	end
end

local function AddPlaceholderTower(Name)
	
	TowerInfoEvent.OnClientEvent:Connect(function(TowerName)
		local ExistingTowers = TowersFolder:FindFirstChild(TowerName)
		
		if ExistingTowers then
			RemovePlaceholder()
			TowerToSpawn = ExistingTowers:Clone()
			TowerToSpawn.Parent = workspace.Towers

			TowerToSpawn.Outline.OutlineColor = TowerName
		end
	end)
end

local function ColorPlaceholder(color)
	for i, Object in ipairs(TowerToSpawn:GetDescendants()) do
		if Object:IsA("BasePart") then
			PhysicsEngine:SetPartCollisionGroup(Object, "Tower")
			Object.Color = color
		end
	end
end

TowerInfoEvent.OnClientEvent:Connect(function(Player, TowerName)
	Gui.TextButton.Activated:Connect(function(P)
		AddPlaceholderTower(TowerName)
	end)
end)

UserInputService.InputBegan:Connect(function(Input, Processed)
	if Processed then
		return
	end

	if TowerToSpawn then
		if Input.UserInputType == Enum.UserInputType.MouseButton1 then
			if CanPlace then
				PlaceTowerEvent:FireServer(TowerToSpawn.Name, TowerToSpawn.PrimaryPart.CFrame)
				RemovePlaceholder()
			end
		elseif Input.KeyCode == Enum.KeyCode.R then
			Rotation += 90
		elseif Input.KeyCode == Enum.KeyCode.Q then
			Rotation -= 90
		end
	end

end)

RunService.RenderStepped:Connect(function()
	if TowerToSpawn then
		local Result = MouseRaycast({TowerToSpawn})
		if Result and Result.Instance then
			if Result.Instance.Parent.Name == "TowersArea" then
				CanPlace = true
				ColorPlaceholder(Color3.fromRGB(255, 255, 255))
			else
				CanPlace = false
				ColorPlaceholder(Color3.fromRGB(255, 0, 0))
			end
			local X = Result.Position.X
			local Y = Result.Position.Y + TowerToSpawn.Humanoid.HipHeight + (TowerToSpawn.PrimaryPart.Size.Y /2)
			local Z = Result.Position.Z

			local Cframe = CFrame.new(X, Y, Z) * CFrame.Angles(0, math.rad(Rotation), 0)
			TowerToSpawn:SetPrimaryPartCFrame(Cframe)
		end
	end
end)

Signal Sender (Inside of PlaceButton GUI) (Server Script)

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicatedStorage:WaitForChild("Remote")

local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")

local TowerInfoEvent = Remotes:WaitForChild("TowerInfo")

local TowersFolder = ReplicatedStorage:WaitForChild("Towers")

local SignalEvent = script.Parent.Signal

SignalEvent.OnServerEvent:Connect(function(TowerName)

local ConfirmedTowers = TowersFolder:FindFirstChild(TowerName)
local ConfirmedTowersName = ConfirmedTowers.Name -- attempt to index nil with 'Name'

TowerInfoEvent:FireClient(ConfirmedTowersName)

end)

Signal Retriever (Client) (Also inside of PlaceButton)

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicatedStorage:WaitForChild("Remote")

local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")

local TowerInfoEvent = Remotes:WaitForChild("TowerInfo")

local TowersFolder = ReplicatedStorage:WaitForChild("Towers")

local SignalEvent = script.Parent.Signal

script.Parent.Activated:Connect(function()

SignalEvent:FireServer("Outrider")

end)

Tower Module (Inside of serverscriptservice)

local Towers = {}

local PhysicsService = game:GetService("PhysicsService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TowersFolder = ReplicatedStorage.Towers

local Remotes = ReplicatedStorage:WaitForChild("Remote")
local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")

function Towers.PlaceDown(Player, TowerName, Cframe)
	local WantedTower = Towers:FindFirstChild(TowerName)

	if WantedTower then
		local ClonedTower = WantedTower:Clone()
		ClonedTower.HumanoidRootPart.CFrame = Cframe
		ClonedTower.Parent = workspace.Towers
		ClonedTower.HumanoidRootPart:SetNetworkOwner(nil)

		for i, EveryParts in ipairs(ClonedTower:GetDescendants()) do
			if EveryParts:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(EveryParts, "Towers")
			end
		end
	end
end

PlaceTowerEvent.OnServerEvent:Connect(Towers.PlaceDown)

return Towers

In the FireClient you have to put Player

It made the “Argument 1 missing or nil” error again

Maybe this is because you’re trying to define a string with .Name? (wait sorry im just a bit busy i’ve missed the error gimme 5 sec)

Yeah try to remove .Name

You don’t fire to the server the player, the player is automatically sent to the server.

1 Like

Thanks for the advice (sorry for the late reply I have school), I fixed some codes and it worked, but there’s another problem again, when I tried to place the Tower down it didn’t work It just stayed at “Placing View”

Here is the problematic code
If I remove the CanPlace line it made some error, and It still doesn’t work even If I put CanPlace line

Error without the CanPlace line:
ServerScriptService.Functions.TowersFunction:11: attempt to call missing method ‘FindFirstChild’ of table

if TowerToSpawn then
		if Input.UserInputType == Enum.UserInputType.MouseButton1 then
			if CanPlace then -- This CanPlace line
				PlaceTowerEvent:FireServer(TowerToSpawn.Name, TowerToSpawn.PrimaryPart.CFrame)
				
			elseif Input.KeyCode == Enum.KeyCode.R then
				Rotation += 90
			elseif Input.KeyCode == Enum.KeyCode.Q then
				Rotation -= 90
			end
		end
	end

(I’m sorry If I waste your time)