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

Why Is this Not Working?

local player = game.Players:GetChildren()
local playercharacter = player.Character
repeat wait()
until game.Workspace:FindFirstChild("WinerMessage")~= nil
if game.Workspace:FindFirstChild("WinerMessage")~= nil then
	playercharacter.Humanoid.Health = 100
end

this script is in ServerScriptService this is a scipt for all the players that are in the game. so when the wintermessage is visible in workspace then all of they players ingame their health should go to 100.

1 comment

0

The "GetChildren" method returns (outputs) a table (a list of values), so there are no properties/children of that table (as a whole). Find out more about tbales here ----> http://wiki.roblox.com/index.php?title=Table

1 answer

✓ Accepted answer

If you read my comment above, you've probably figured out the problem. What I'll do to help is show you the best ways to fix your script.

First, whenever you come across problems like these, the best way you can deal with them is to follow these specific steps:

Locate the problem - We'll find out what the problem is and *where * it is

Discuss the problem - Next, we'll discuss what might be the error

Solve the problem - We'll put together everything we've said in the discussion and implant the solution into the script

Those are the three main steps we as a community should take when were asking and answering questions.

Now that we know these *steps to success *, let's use them. First off, let's focus on the first step;Locate the problem...

In line 1, the script errors and says that it "attempts to index a table/array" or something like that :/.

Ok, next let's discuss why it's erroring...

Since the GetChildren method holds values, it can't define or operate (change) all the values as a whole. For in example, if we had a table named "TableValues" that is holding two values, one being a part and the other being an IntValue (# value). If we do TableValue.Character, it would error, because no all of the values within that table have the child/property ".Character".

Now how do we implant this onto our script...?

We know that we're using tables and that we can't operate on a table as a whole, we have to index specifc (specify) values in that table - so we'd use an Iteration (more on iterators here ---> http://wiki.roblox.com/index.php?title=Generic_for) specificly, we'd use the for i,v in pairs() do .

  • EXAMPLE -
Table = game.Players:GetChildren() --First we create a table that has a list of all the players in - game

for i,v in pairs(Table) do --"I" would stand for # of value you r on, and "v" would stand for the specific value your on

	local player = v --player will stand for the "value" (v) we're on
end

So the everything together would look something like this...

player = game.Players:GetChildren()

for i,v in pairs(player) do
	repeat wait() until v.Character ~= nil
	local playercharacter = v.Character
	repeat wait() until game.Workspace:FindFirstChild("WinerMessage")~= nil
		if game.Workspace:FindFirstChild("WinerMessage")~= nil then
  	  		playercharacter.Humanoid.Health = 100
end

Hopefully all this made since and helped a lot. If you have any other questions, comments, or suggestions drop a comment down below. Otherwise, I have some links to the wiki that will hopefully help a bit:

Roblox wiki

Tables

GetChildren

4 comments

0

i understand the for i,v in pairs now thanks for that but the script will still not give all players 100 health if there health is under 100

0

what does the output menu say?

0

nothing

0

The script should run fine if you include all of the bool/"if then statement" reqiurements (WinerMessage). Here are some little things that may cause the script to not work: -(script disabled) -(bool requirements not met) -(the player's character is not loaded) -(the player is dead;has 0 health)

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