I can't pass "self.Instance" into RemoteEvents

I want to pass in the player’s tool to the server through remote events. The self.tool isn’t nil when used in the module script, but becomes nil whenever it gets passed into a remote.

65ad443f7a5050441319839eed833ad6

The script works perfectly fine when the tool is placed in StarterPack but ends up breaking whenever I make a script that gives it to individual teams.

Here’s my constructor for the module script, let me know if I’m setting up my constructor correctly. I’m not really trying to use OOP.

function Melee:init(player, tool)
	if tool then
		self.player = player;
		self.tool = tool;
		self.config = tool.Settings;
		self.handle = tool.Handle;
		
		self.tool.CanBeDropped = false;

		print("Tachi has been initialized.");

	end
end

This is the remote that I’m trying to fire, passing the self.tool through tool.

soundRemote.OnServerEvent:Connect(function(player, tool, damageType)
	print("tool", tool);
	if tool then
		if damageType == "Slash" then
			print("slash slash fired");
			local slashSound = tool.Handle.Slash;
			slashSound:Play();
		end
		
		if damageType == "Lunge" then
			print("sound lunge fired;")
			local lungeSound = tool.Handle.Lunge;
			lungeSound:Play();
		end
	end
end)

This is where I’m firing the remote event from the module script. As you can see I’m passing in self.tool.

function Melee:lunge()
	print("passed lunge function");
	if not canClick then
		print("lungeedddd", self.tool);
		canClick = true;
		damageType = "Lunge";
		soundRemote:FireServer(self.tool, damageType);
	
		if not isFlickPlaying then
			local anim = Instance.new("StringValue")
			anim.Name = "toolanim"
			anim.Value = "Lunge"
			anim.Parent = self.tool;
		end
	
		wait(self.getAttackCooldown);
		gripOut:FireServer(self.tool);
		print("passed fireServer, grip out");
		wait(self.getLungeDuration);
		gripUp:FireServer(self.tool);
	
		damageType = "Slash";
		canClick = false;
	end

end
``

Have you tried this possible solution?

local a = self.tool
-- Then send 'a' through remote event as tool.

Yeah I tried that, it didn’t work. It still returns as nil.

Are you making the instance locally? If so you will get nil since the server can’t get a reference to it.

1 Like

What do you mean locally? In Melee:init(), I passed in the tool into the module script and declare it as self.tool so I can reuse it throughout the module script. Shouldn’t the remote event able to read arguments that from the client?

Are you creating the tool in a localscript.

Yeah, I’m creating the tool in localscript.

I guess the server doesn’t recognize the tool, because it’s not rendered server-side. By rendered I mean that the server doesn’t see the tool in Explorer (where you parented it).

3 Likes

I thought you can pass client’s instances into remote events, or I’m wrong? So I can’t pass in the whole tool into the remote event?

Nope, you’re just setting a path to it. A RemoteEvent can’t render an instance from a local client. You need to create the tool server-sided and then pass the tool to your other scripts.

2 Likes