Argument 1 Missing Or Nil when firing a module script

I have a module script that I use for skills and right now I have a skill which shoots off an attack which is located at your mouse position, with a function in the tool and a script which identifies the function even though I dont know its needed it comes out with the error :
Argument 1 Missing Or Nil

This is the tool’s children :

image
The mouse script :

local Tool = script.Parent

local MouseLoc = Tool:WaitForChild("MouseLoc")

function MouseLoc.OnClientInvoke()
	return game:GetService("Players").LocalPlayer:GetMouse().Hit.
end

The module script :

function module.RealSlash(player)
	for i,v in pairs(game.Players:GetChildren()) do
		local char = v.Character or v.CharacterAdded:Wait()
		if char:FindFirstChild("Real Knife") then
			local tool = char:FindFirstChild("Real Knife")
			v.leaderstats.PlayerValues.TP.Value = v.leaderstats.PlayerValues.TP.Value - 25
			local debounce = false
			local MouseLoc = tool:WaitForChild("MouseLoc")

			local character = script.Parent.Parent
			local targetPos = MouseLoc:InvokeClient(game:GetService("Players"):GetPlayerFromCharacter(character))
			local lookAt = (targetPos - character.Head.Position).unit
			local star = game.ServerStorage.StarShot:Clone()
			local dmg = game.ServerStorage.StarDamage:Clone()
			local destroy = game.ServerStorage.StarDestroy:Clone()

			if not debounce then
				debounce = true

				star.Material = "Neon"
				star.Anchored = false
				star.CanCollide = false
				
				local spawnPos = script.Parent.Handle.Position
				spawnPos  = spawnPos + (lookAt * 5)

				star.Name = "SoulSwordStar"

				local antiGravity = Instance.new("BodyForce")
				antiGravity.Force = Vector3.new(0, workspace.Gravity * star:GetMass(), 0)
				antiGravity.Parent = star
				star.Velocity = lookAt  * 100

				destroy.Parent = star
				dmg.Parent = star
				star.Color = script.Parent.BladeValue.Value
				star.Parent = workspace
				star:SetNetworkOwner((game:GetService("Players"):GetPlayerFromCharacter(character)))
				game:GetService("Debris"):AddItem(star, 10)
				star.Position = script.Parent.Parent.HumanoidRootPart.Position
				wait(0.75)
				debounce = false
			end
		else
			continue
		end
	end
end

return module

Help would be greatly appreciated thank you! : D

Could you please specify which script your getting this error from and on which line of code?

1 Like

Remove the “.” on the last part

1 Like

The module script on line 11 for the script I sent.

game:GetService("Players"):GetPlayerFromCharacter(character)

Means this is returning nil.
You need to wrap it in an ‘if’ statement check first.

local plr = --Fetch player from character.
if plr then --Invoke client if a player is found.
1 Like

Still doesnt work sadly as the error is from the module script

I’ll try this and give it a shot.

If the function returns ‘nil’ it means you aren’t passing it a valid character of some player. In other words, the following assignment isn’t a reference to some player’s character model.

local character = script.Parent.Parent
1 Like

Oh yeah right I did a bit of an oopsie with that I just gotta figure out how to find character from module now
Nvm I already identified character its just that my friend did two

I’ve pretty much sorted it just gotta smooth it out now and get rid of the errors thank you!