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