This script should be passing 2 values when f is pressed , however every time I press f, the arguments return nil

Argument 1 missing or nil

Can anyone tell me why? Thanks in advance!


local Hotbar =  player.PlayerGui.HotbarUI.Hotbar
   local e = game.ReplicatedStorage:WaitForChild("ChangeToolEvent")

function onKeyPress(inputObject, gameProcessedEvent)
if  inputObject.KeyCode == Enum.KeyCode.W then
		script.Asset.Value = ("Forward")
		elseif  inputObject.KeyCode == Enum.KeyCode.S then
		script.Asset.Value = ("Backward")
elseif  inputObject.KeyCode == Enum.KeyCode.F then
	local V1 = Hotbar.CurrentSlot.Itemtype.Value
	local V2 = Hotbar.CurrentSlot.CurrentItem.Value
		e:FireServer(V1,V2)
end

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

	

--The Event


function weld(p1,p2,c0)
	local w = Instance.new("Weld",p1)
	w.Part0 = p1
	w.Part1 = p2
	w.C0 = c0 or p1.CFrame:inverse() * p2.CFrame
	return w
end



local event = game.ReplicatedStorage:WaitForChild("ChangeToolEvent") event.OnServerEvent:connect(function(player,arguments) 
	print(arguments[1])
	print(arguments[2])
	local F = game.ServerStorage.GlobalStorage:WaitForChild(arguments[1])
	local Target = F:WaitForChild(arguments[2]):Clone()
	
	for _,v in pairs(Target:GetChildren()) do
		if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
			v.Anchored = true
			
		end
	end
	
	Target.Parent = player.Character.PlayerEquipment

	for _,v in pairs(Target:GetChildren()) do
		if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
			if v ~= Target["EquipmentCore"] then
				weld(v, Target["EquipmentCore"])
			end
		end
	end
	
	local TargetWeld = weld(Target["EquipmentCore"], player.Character["RightHand"], CFrame.new())
	
	for _,v in pairs(Target:GetChildren()) do
		if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
			v.Anchored = false
			v.CanCollide = false
			
			--print ("Welded "..WD.Value)
		end
	end	
end)

3 comments

0

What is the OnServerEvent of ChangeToolEvent? You may also want to print V1 and V2 right before firing the event to check if it is actually nil.

0

I've updated the question with the event. I printed them and they both came back nil.

0

You're passing two arguments into FireServer. OnServerEvent expects three arguments: the player, and the two arguments you passed. It should be event.OnServerEvent:connect(function(player, firstargument, secondargument).