Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

10:24:07.853 - is not a valid member of Players error?

So recently I got someone to help me out on my latest script it did work but some kind of error was appearing in the output something like this 10:24:07.853 - is not a valid member of Players I'm not sure how to fix this please help me out

for i,x in pairs(game.Workspace.NPCs:GetChildren()) do
	x.Region.Touched:connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			local tab = {}
			for o,p in pairs(x.QuestLine:GetChildren()) do
				for s,q in pairs(p:GetChildren()) do
					local texttab = {
					Text = q.Value.. " ",
					Colored = {},
					}
					for v,r in pairs(q.Colored:GetChildren()) do
						local colortab = {
						    Word = r.Name.." ",
						    Color = r.Value,
						}
						table.insert(texttab.Colored,colortab)
					end
					table.insert(tab,texttab)
				end
				game.ReplicatedStorage.NPCSpeak:FireClient(game.Players[hit.Parent.Name],tab)
			end
		end
	end)
end

Please help soon as possible!

3 comments

0

maybe a npc touched it and triggered the function, cuz npcs also have humanoids

0

I cant read the script, can you add a code block?

0

ohh ok

2 answers

From what I can tell, something that wasn't supposed to touch it did, causing it to return an error. To prevent this, you could have the code restrict it to a specific name of a part, or a specific value being in the part.

If this is for a touch of a player, or an NPC, which it seems to be, then filter Players to see if the name of the player exists, if it doesn't don't run the script.

If this is for the touch of a specific NPC, only run for the name of the model. An example of NPC's are below.

Player:

if hit.Parent.Name == "npcname here" then
	-- the code here, place this below line 3
end

Thanks for the help everyone but I have solved this issue, all I did is remove the spaces and that solved it :D

This discussion is preserved as it was. New answers, comments, and votes are closed.