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.
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
``