In pairs loop not working in module scripts?

I’m trying to check for a player with a simple in pairs loop in a module script but for some reason it doesnt work, the code looks fine to me so i have no clue what the issue is

	for i,v in pairs(game.Workspace.Alive:GetChildren()) do
		if v:FindFirstChild("HumanoidRootPart") then
			print(v.Name)
		end
	end

you have to call the module script from a script/localscript.
like so

-- Script
local Module = require(game.ReplicatedStorage.Module)
Module.HRPFunc()
-- ModuleScript
local module = {}
function module.HRPFunc = function()
for i,v in pairs(game.Workspace.Alive:GetChildren()) do
		if v:FindFirstChild("HumanoidRootPart") then
			print(v.Name)
		end
	end
end
return module

it’s being called from a server script, that’s only a snip bit of the code but im using a function

module.Active = function(player,Character)

you’re passing the player and his character as args and in the module you’re checking for something different.
can i see your full code?

yeah sure, it’s a little more simplified but its meant for a skill

module.Active = function(player,Character)
	local character = player.Character
	CastingModule.Signs(player,0.2,3)
	task.wait(0.3)
	--// Stuns

	local Slowdown = Instance.new("NumberValue")
	Slowdown.Name = "SpeedBoost"
	Slowdown.Value = -character.Humanoid.WalkSpeed * .8
	Slowdown.Parent = character.Effects
	game.Debris:AddItem(Slowdown,.8)

	create("Attacking", 1, character)
	create("NoDash", .6, character)

	--// Visual


	local startAnim = hum:LoadAnimation(script.Animation)
	startAnim:Play()
	startAnim.Priority = Enum.AnimationPriority.Action2
	startAnim:AdjustSpeed(1)

	local GustEffect = script.Gust:Clone()
	GustEffect.Parent = workspace.GarbageCollector
	GustEffect.CFrame = humrp.CFrame * CFrame.new(0,0,-3)
	local Weld = Instance.new("WeldConstraint",GustEffect)
	Weld.Part0 = GustEffect
	Weld.Part1 = humrp
	GustEffect.WindBlow:Play()


	for i,v in pairs(game.Workspace.Alive:GetChildren()) do
		if v:FindFirstChild("HumanoidRootPart") then
			print(v.Name)
		end
	end
end
	
return module

the full module is not working?

there are no erros in the code, it just simply skips the loop, i’ve tested with prints

it works, but just doesnt perform the loop, thats the problem

its skipping it because it didn’t find HumanoidRootPart
are you sure that your Instance contains HRP?

yes it’s a folder that players are put into once they join the game, i also put the print before during the in pairs do part to see if that was the issue and it didnt print anything out

you tried to add a print before the if statement?

for i,v in pairs(game.Workspace.Alive:GetChildren()) do
	print(v.Name)
end

yeah i did the exact thing you just posted

maybe you’re putting the players into that folder through a localscript once they join the game?

oh yeah i just found out that i am, is that the isuse?

yeah it is, cuz the server cannot detect the changes that are being made through the client,
make sure to make it a server script.

1 Like

yeah it worked, thank you a lot :sweat_smile:

1 Like