Finding player in a modulescript

hi.

im having trouble getting the player in a modulescript. it is being required by a legacy script. the player turns up nil. what i am trying to achieve is doing certain things with the player’s character, most importantly.

my main objective is getting HRP in said modulescript. please help.

this is how its being required (triggers when the humanoid has died)

Players.PlayerAdded:Connect(function(player)
	--function is present to define who each player is.
	player.CharacterAdded:Connect(function(character)
		--function is present to define if the player's character died.
		character:WaitForChild("Humanoid").Died:Connect(function(died)
		print("Humanoid has Died.")
		local Var = math.random(1,1) -- dont worry im not insane this is for testing 
		
		--rolling to see if finality mode will activate.
		if Var == 1 then
			print("Finality.")
			local Svar = math.random(2,2)
				if Svar ~= 1 then
					require(FMS1CS).cutsceneVFX()
				end		

thats the only part of that script you need to see.

modulescript:

local module = {}

--this module's purpose is to trigger the VFX at the cutscene position when activated.


print("recivedsignal")

function module.cutsceneVFX(player, character)
	local anim = script.FMS1A
	local HCF = character.HumanoidRootPart.CFrame

again, im not showing the complete script, thats all you need to see.

please tell me how my goal can be accomplished

You never feed the player instance and the character instance into the function you called. I would expect something along the lines of:

if Svar ~= 1 then
	require(FMS1CS).cutsceneVFX(<player instance>, <player character>)
end		

im a bit confused. what should i put in place of player instance and player character? im relatively new to scripting.

hello? do you understand my question? should i rephrase?

Perhaps the player left from the game? Could you tell me at which line that errors “player is nil”

no… the im in the game all throughout testing…
it shows nil whenever i try to reference it in the modulescript, so for example,

function test(player)
local character = player.Character

somthing like that, it will show up as nil. i just need to find a reliable way to reference that player/character from a module…

nobady has been able to help me on topics ive posted so far… i honestly need an explanation of how i would do this, not just a line of code… sorry?

ModuleScripts have different script contexts, so you have to pass the player argument for it to work

In this example, the player isn’t passed as an argument so the player is nil

local function test(player)
      print(player)
end

test()

Notice how the parentheses are empty when calling the function test()

Here is an example without this issue present;

local function test(player)
     print(player)
end

test(player)

Now the player variable is accordingly passed as an argument, the first example would work if there wasn’t a ModuleScript involved but as each script has its separate context the second example is needed and the player variable must be passed as an argument

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.