Server Script not recognizing all functions in a module

So… I’ve been trying to learn to use modules to make abilities and powers and stuff, and for some reason the server script that receives the stages of the ability (start, doing it, end) is finding a nil value? The problem is the module script, the function that I’m trying to call is set inside of another module. When I trying Abilities. it shows me the function that I’m trying to call, but it doesn’t do what needs to be done.

Here’s the server script:

-- Services --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- Modules --
local Abilities = require(script:FindFirstChild("Abilities"))

-- Events --
local Event_FOLDER = ReplicatedStorage.Events
local Required_Event = Event_FOLDER.Siphoner_Event

-- Script --
Required_Event.OnServerEvent:Connect(function(Player, Action, Misc1, Misc2)
	
	if Action == "Siphon" then
		Abilities.Siphon(Player.Character, Misc1, Misc2)
	end
	
	if Action == "Siphoning" then
		print(Action, Abilities, Player, Player.Character, Misc1, Misc2)
		Abilities.Siphoning(Abilities, Player.Character, Misc1)
	end
	
	if Action == "Stop Siphon" then
		Abilities.Stop_Siphoning(Player.Character)
	end
	
end)

The print() only prints out one function for the module

Module Script:

-- services --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

-- modules --
local CameraShaker = require(ReplicatedStorage.Modules.CameraShaker)
local PlayerEffects = require(ReplicatedStorage.Modules.PlayerEffects)

-- variables --
local CamShake = ReplicatedStorage.Events.CamShake

local Animatoins = script.Animations
local Effects = script.Effects
local Sounds = script.Sounds

-- module --
local Abilities = {}

Abilities.Siphon = function(Character : Model, Target : Model, TargetType : string)
	Character:SetAttribute("CanAttack", false)
	Character.Humanoid.WalkSpeed = 0
	Character.Humanoid.JumpPower = 0
	
	PlayerEffects.Siphon(Character)
	
	if Character.Powers.Misc:FindFirstChild("Shift To Sprint") then
		Character.Powers.Misc:FindFirstChild("Shift To Sprint").Disabled = true
	elseif Character.Powers.Abilities:FindFirstChild("Vamp Speed") then
		Character.Powers.Abilities:FindFirstChild("Vamp Speed").Disabled = true
	end
	
	local Player = game.Players:GetPlayerFromCharacter(Character)
	CamShake:FireClient(Player, "Shake", "Earthquake")
	
	if TargetType == "Player" then
		Target:SetAttribute("CanAttack", false)
		Target.Humanoid.WalkSpeed = 0
		Target.Humanoid.JumpPower = 0
		
		local TargetPlayer = game.Players:GetPlayerFromCharacter(Character)
		CamShake:FireClient(TargetPlayer, "Shake", "Earthquake")

		if Target.Powers.Misc:FindFirstChild("Shift To Sprint") then
			Target.Powers.Misc:FindFirstChild("Shift To Sprint").Disabled = true
		elseif Target.Powers.Abilities:FindFirstChild("Vamp Speed") then
			Target.Powers.Abilities:FindFirstChild("Vamp Speed").Disabled = true
		end
		
		TweenService:Create(Character.HumanoidRootPart, TweenInfo.new(1), {CFrame = CFrame.lookAt(Character.HumanoidRootPart.Position, Target.HumanoidRootPart.Position)}):Play()
	end
	
	if TargetType == "Object" then
		TweenService:Create(Character.HumanoidRootPart, TweenInfo.new(1), {CFrame = CFrame.lookAt(Character.HumanoidRootPart.Position, Vector3.new(Target.Position.X, Character.HumanoidRootPart.Position.Y,Target.Position.Z))}):Play()
	end
	
	function Abilities:Siphoning(Character : Model, SiphonFrom : string)
		print(Target)
		if SiphonFrom == "Magic" then
			if Target:GetAttribute("Magic") then
				Target:SetAttribute("Magic", Character:GetAttribute("Magic") - 1)
				Character:SetAttribute("Magic", Character:GetAttribute("Magic") + 1)
			end
		end
		
		if SiphonFrom == "Energy" then
			if Target:GetAttribute("Energy") then
				Target:SetAttribute("Energy", Character:GetAttribute("Energy") - 1)
				Character:SetAttribute("Magic", Character:GetAttribute("Magic") + 1)
			end
		end
		
		if SiphonFrom == "Health" then
			Target.Humanoid:TakeDamage(1)
			Character:SetAttribute("Magic", Character:GetAttribute("Magic") + 1)
		end
	end
	
	function Abilities:Stop_Siphoning (Character : Model)
		Character:SetAttribute("CanAttack", true)
		Character.Humanoid.WalkSpeed = 16
		Character.Humanoid.JumpPower = 50

		if Character.Powers.Misc:FindFirstChild("Shift To Sprint") then
			Character.Powers.Misc:FindFirstChild("Shift To Sprint").Disabled = false
		elseif Character.Powers.Abilities:FindFirstChild("Vamp Speed") then
			Character.Powers.Abilities:FindFirstChild("Vamp Speed").Disabled = false
		end
		
		CamShake:FireClient(Player, "End")
		
		PlayerEffects.StopSiphon(Character)

		if TargetType == "Player" then
			local TargetPlayer = game.Players:GetPlayerFromCharacter(Character)
			CamShake:FireClient(TargetPlayer, "End")

			Target:SetAttribute("CanAttack", true)
			Target.Humanoid.WalkSpeed = 16
			Target.Humanoid.JumpPower = 50
			
			if Target.Powers.Misc:FindFirstChild("Shift To Sprint") then
				Target.Powers.Misc:FindFirstChild("Shift To Sprint").Disabled = false
			elseif Target.Powers.Abilities:FindFirstChild("Vamp Speed") then
				Target.Powers.Abilities:FindFirstChild("Vamp Speed").Disabled = false
			end
		end
	end
end

return Abilities

The error that I receive is ServerScriptService.Server.Species.Siphoner.SiphonerServer:21: attempt to call a nil value ( this is the line in the server script that calls the Siphoning function )

All help would be greatly appreciated

You seem to have nested your function definitions which may be the cause of the issue.

how would I un-nest them? I’ve never really heard of the term before

Define the Abilities.Siphoning function after you finish defining the Abilities.Siphon function. At the moment you define Siphoning from within Siphon

What line exactly are you getting the error?

line 21 in the server script, the line that calls the Siphoning function

I’ll try that, might have to change few things around but if it works I’ll mark this as a solution

1 Like

You have a “Siphon” function, but you’re missing the “Siphoning” and “Stop Siphon”. So when you get to the two other if statements, it’s nil because they don’t exist. Add those two functions to your module to fix the error.

1 Like