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