Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Argument 1 missing or nil explanation and fix?

I am making a sandbox game, and when i press a button, it should make the item that a player is placing higher or lower. This is the Client Placing Script:

local player = script.Parent.Parent.Parent
local placementHandler = require(script:WaitForChild("PlacementModule"))
if player.team == game.Teams.Lavender then
	base = workspace.Lavender
elseif player.team == game.Teams.Mint then
	base = workspace.Mint
elseif player.team == game.Teams.Toothpaste then
	base = workspace.Toothpaste
elseif player.team == game.Teams.White then
	base = workspace.White
end
local items = game:GetService("ReplicatedStorage").Items
local plane = placementHandler.new(base.Baseplate, base.ItemHolder, 1)
local dummyModel
local signal
local currentItemName

local function cancelPlacement()
	if (currentItemName) then
		plane:disable()
		if (dummyModel.Parent) then
			dummyModel:Destroy()
		end
		dummyModel = nil
		signal = nil
		currentItemName = nil
	end
end

local function initiatePlacement(itemName)
	cancelPlacement()
	
	dummyModel = items[itemName]:clone()
	
	currentItemName = itemName
	
	for _, object in pairs(dummyModel:GetChildren()) do
		if (object:IsA("BasePart")) then
			object.CanCollide = false
		end
	end
	
	--
	
	local function onKeyPress4(inputObject, gameProcessedEvent)
		if inputObject.KeyCode == Enum.KeyCode.Up then
			dummyModel.MainPart.Position =  Vector3.new(dummyModel.MainPart.Position.X,dummyModel.MainPart.Position.Y + 1,dummyModel.MainPart.Position.Z)
		end
	end

	game:GetService("UserInputService").InputBegan:connect(onKeyPress4)
	
	local function onKeyPress5(inputObject, gameProcessedEvent)
		if inputObject.KeyCode == Enum.KeyCode.Down then
			dummyModel.MainPart.Position =  Vector3.new(dummyModel.MainPart.Position.X,dummyModel.MainPart.Position.Y - 1,dummyModel.MainPart.Position.Z)
		end
	end

	game:GetService("UserInputService").InputBegan:connect(onKeyPress5)
	
	--
	
	dummyModel.Parent = workspace
	
	local signal = plane:enable(dummyModel)
	
	signal:connect(function(location, _)
		game:GetService("ReplicatedStorage").ClientPlaced:FireServer(currentItemName, location)
	end)
end

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.P then
		initiatePlacement("Platform")
	end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

function onKeyPress2(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.L then
		initiatePlacement("Lava")
	end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress2)


game:GetService("UserInputService").InputBegan:connect(onKeyPress)

function onKeyPress3(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Q then
		cancelPlacement()
	end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress3)

player.Character:WaitForChild("Humanoid").Died:connect(function()
	cancelPlacement()
end)

This is the server placement script:

local items = game:GetService("ReplicatedStorage").Items

game:GetService("ReplicatedStorage").ClientPlaced.OnServerEvent:connect(function(player, itemName, location)
	local itemTemplate = items:FindFirstChild(itemName)
	
	if (itemTemplate) then
		local item = itemTemplate:clone()
		if player.team == game.Teams.Lavender then
			item.Parent = workspace.Lavender.ItemHolder
		elseif player.team == game.Teams.Mint then
			item.Parent = workspace.Mint.ItemHolder
		elseif player.team == game.Teams.Toothpaste then
			item.Parent = workspace.Toothpaste.ItemHolder
		elseif player.team == game.Teams.White then
			item.Parent = workspace.White.ItemHolder
		end
		item:SetPrimaryPartCFrame(location.X,location.Y,location.Z)
	end
end)

This is the part of the scripts that I'm worried about:

Client:

local function initiatePlacement(itemName)
	cancelPlacement()
	
	dummyModel = items[itemName]:clone()
	
	currentItemName = itemName
	
	for _, object in pairs(dummyModel:GetChildren()) do
		if (object:IsA("BasePart")) then
			object.CanCollide = false
		end
	end
	
	--
	
	local function onKeyPress4(inputObject, gameProcessedEvent)
		if inputObject.KeyCode == Enum.KeyCode.Up then
			dummyModel.MainPart.Position =  Vector3.new(dummyModel.MainPart.Position.X,dummyModel.MainPart.Position.Y + 1,dummyModel.MainPart.Position.Z)
		end
	end

	game:GetService("UserInputService").InputBegan:connect(onKeyPress4)
	
	local function onKeyPress5(inputObject, gameProcessedEvent)
		if inputObject.KeyCode == Enum.KeyCode.Down then
			dummyModel.MainPart.Position =  Vector3.new(dummyModel.MainPart.Position.X,dummyModel.MainPart.Position.Y - 1,dummyModel.MainPart.Position.Z)
		end
	end

	game:GetService("UserInputService").InputBegan:connect(onKeyPress5)
	
	--
	
	dummyModel.Parent = workspace
	
	local signal = plane:enable(dummyModel)
	
	signal:connect(function(location, _)
		game:GetService("ReplicatedStorage").ClientPlaced:FireServer(currentItemName, location)
	end)
end

Server:

item:SetPrimaryPartCFrame(location.X,location.Y,location.Z)

When i press the button, it works to make the dummy model go up, but when I try to place the item, it gives the error message:

15:51:58.268 - Argument 1 missing or nil

15:51:58.268 - Stack Begin

15:51:58.269 - Script 'ServerScriptService.ServerPlacement', Line 17

15:51:58.269 - Stack End

Please help me, I need to know how to fix this.

2 answers

✓ Accepted answer

Apart from the bug correctly pointed out by Gioni01, there is another error.


local plane = placementHandler.new(base.Baseplate, base.ItemHolder, 1)

This line indicated you make a call to your modulescript to return a plane object.

Then the lines:

    local signal = plane:enable(dummyModel)

    signal:connect(function(location, _)
        game:GetService("ReplicatedStorage").ClientPlaced:FireServer(currentItemName, location)
    end)

indicate that you store the signal in a variable, and when it fires you connect a function. Now I will assume you use something like Tunicus' Placement Handler:

https://www.roblox.com/library/1122124371/Placement-Handler-V2

In the documentation provided in that module you will find that your signal, when fired, will return an array of CFrames. You however are expecting a tuple of CFrames in your code.

Instead, use:

    local signal = plane:enable(dummyModel)

    signal:Connect(function(locations)
        game:GetService("ReplicatedStorage").ClientPlaced:FireServer(currentItemName, locations[1])
    end)

Hope this helps, good luck!


Edit:

I never used this plugin, but I'm guessing you should make sure to disconnect the function from the signal event again after you are done placing your item. To do that save your connection in a local variable. Something like (I think:)

local signal = plane:enable(dummyModel)
local conn = signal:Connect(function(locations)
    game:GetService("ReplicatedStorage").ClientPlaced:FireServer(currentItemName, locations[1])
    conn:Disconnect()
end)
item:SetPrimaryPartCFrame(CFrame.new(location.X,location.Y,location.Z))

3 comments

0

now, the object doesn't place.

0

at least there's no error messages

0

also i already tried that

This discussion is preserved as it was. New answers, comments, and votes are closed.