KOzero
|
  |
| Joined: 11 May 2010 |
| Total Posts: 1411 |
|
|
| 18 Sep 2014 12:00 PM |
I've had enough trying to figure the problem and I politely request help find a solution to my problem. You see the first if statement, that whole chunk of the that piece of code won't run.
local Remotes = game.ReplicatedStorage.Remotes local Players = game.Players:GetPlayers() Remotes.SendMsg.OnServerEvent:connect(function(Player,...) print(1)----------------------------------------------------------Prints for i,v in pairs(Players) do print(2)--------------------------------------------------Doesn't print if Test.TextBounds.X >= 430 then ----------------Skips this chunk from here print("DoubleLine") local LineDTop = game.ReplicatedStorage.Guis:FindFirstChild("Line0"):Clone() local LineDBottom = game.ReplicatedStorage.Guis:FindFirstChild("Line0"):Clone() LineDTop.Parent = v.PlayerGui.ScreenGui:WaitForChild("Chat_Gui").Chat_Display LineDTop.Name = "Line1" for i = 1,#Test.Text do LineDTop.Message.Text = string.sub(Msg,1,i) if LineDTop.Message.TextBounds.X <= 430 then LineDBottom.Message.Text = string.sub(Msg,Msg:len() - LineDTop.Message.Text:len() + 1,#Msg.Text) end end LineDTop.Plyr.Text = Player.Name":" LineDTop.Message.Size =LineDTop.Message.Size - UDim2.new(0,LineDTop.Plyr.TextBounds.X+3,0,0) LineDTop.Message.Position = LineDTop.Message.Position + UDim2.new(0,LineDTop.Plyr.TextBounds.X+3,0,0) MessageUpdate() LineDBottom.Parent = v.PlayerGui.ScreenGui:WaitForChild("Chat_Gui").Chat_Display LineDBottom.Plyr:Destroy() MessageUpdate() else print("Singleline")----------------------------------------------------Doesn't print local LineSingle = game.ReplicatedStorage.Guis:FindFirstChild("Line0"):Clone() LineSingle.Parent = v.PlayerGui.ScreenGui:WaitForChild("Chat_Gui").Chat_Display LineSingle.Plyr.Text = Player.Name":" LineSingle.Message.Text = Msg LineSingle.Message.Size = LineSingle.Message.Size - UDim2.new(0,LineSingle.Plyr.TextBounds.X+3,0,0) LineSingle.Message.Position = LineSingle.Message.Position + UDim2.new(0,LineSingle.Plyr.TextBounds.X+3,0,0) MessageUpdate() end end------------------------------...until here print(3)------------------------------------------------------------------prints end) |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 18 Sep 2014 12:03 PM |
Print your Test.TextBounds.X before the if block It's always important if you know where something is breaking off to see if your condition is matching up |
|
|
| Report Abuse |
|
|
KOzero
|
  |
| Joined: 11 May 2010 |
| Total Posts: 1411 |
|
|
| 18 Sep 2014 12:08 PM |
| If the first if doesn't match then it should be going to the second condition that starts with else. |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2014 12:32 PM |
Um guys, it's the For loop which is failing.
for i,v in pairs(Players) do print(2)--------------------------------------------------Doesn't print
A For is an if statement as well as an increment, and a stack conditioner,so logic says there r no Pairs to loop thru. no?
OP. your print statements r useless, because they contain no information.......
print(Players, #Players) print(Player[1]) for i,v in pairs(Players) do print(2)--------------------------------------------------Doesn't print
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 18 Sep 2014 12:38 PM |
| Sorry wasn't paying attention may I also note that i has been used twice, and if you're not using i from pairs it is best replaced with _ which has been commonly adapted for garbage variables. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 18 Sep 2014 12:40 PM |
| And you may want to put your local Players = game.Players:GetPlayers() inside of the event, since otherwise it will always return a blank table, surely? |
|
|
| Report Abuse |
|
|
KOzero
|
  |
| Joined: 11 May 2010 |
| Total Posts: 1411 |
|
|
| 18 Sep 2014 12:44 PM |
| Why is that, it can be accessed from within the script but not outside of it so every function inside the script will be able to access it. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 18 Sep 2014 12:46 PM |
| Well, at the moment it seems to be outside of any function. This means that it will be collected when the script is made, and never updated at the point when the event from the server fires. Maybe just update it by putting Players = game.Players:GetPlayers() inside of the function? |
|
|
| Report Abuse |
|
|
KOzero
|
  |
| Joined: 11 May 2010 |
| Total Posts: 1411 |
|
|
| 18 Sep 2014 12:48 PM |
| Text is nil but that's not what caused the for to fail but the Remote event didn't send the args or I don't know how to add args to it. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 18 Sep 2014 12:53 PM |
Put this before print(1) for me? print(game.Players:GetPlayers()) print(Players) And then tell me what they both give you |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2014 12:53 PM |
| As they've already stated, it's most likely because there are no players at the time you defined the variable 'Players'. To check this, you need simply put print(#Players) after the line 'print(1)' |
|
|
| Report Abuse |
|
|
KOzero
|
  |
| Joined: 11 May 2010 |
| Total Posts: 1411 |
|
|
| 18 Sep 2014 01:00 PM |
Actually no, because it doesn't trigger till a player types something in a textbox... Elunate was right about the variable being within the function. I know how to fix the args now, thanks for all your help. |
|
|
| Report Abuse |
|
|
KOzero
|
  |
| Joined: 11 May 2010 |
| Total Posts: 1411 |
|
|
| 18 Sep 2014 01:04 PM |
| I take it back, Elunate you were wrong about the variable being within the function.. |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2014 01:07 PM |
Did you test to see if the table was blank? for i,v in pairs(game.Players:GetPlayers()) do |
|
|
| Report Abuse |
|
|
KOzero
|
  |
| Joined: 11 May 2010 |
| Total Posts: 1411 |
|
|
| 18 Sep 2014 01:18 PM |
Yes, it returned a table id but not didn't work.
|
|
|
| Report Abuse |
|
|
|
| 18 Sep 2014 01:26 PM |
That's because you printed the table, mostly a mistake on his part for telling you to do that. Print the number of objects in the table instead. Like I said. print(#Players) |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2014 01:30 PM |
Your issue is that you define Players as GetPlayers() at the beginning of the script.
You need to put it inside the OnServerEvent() function.
Why?
Because, since the script ran at the beginning of the game, there were no players. The script runs before the players get there, so :GetPlayers() returns a table, but nothing in it. |
|
|
| Report Abuse |
|
|
KOzero
|
  |
| Joined: 11 May 2010 |
| Total Posts: 1411 |
|
|
| 18 Sep 2014 01:38 PM |
| I take it back again, Elunate based on the statement above. |
|
|
| Report Abuse |
|
|
|
| 18 Sep 2014 01:53 PM |
Bleh, Just try my suggestion and get back to us. I refuse to look for other errors until you say that this isn't it. The only reason that 2 wouldn't print is because your for loop isn't running. |
|
|
| Report Abuse |
|
|
KOzero
|
  |
| Joined: 11 May 2010 |
| Total Posts: 1411 |
|
|
| 18 Sep 2014 02:18 PM |
I'm glad your intrigued to this thread, the for loop would't run because I set the variable Players = game.Players:GetChildren() at the top of the script which has nothing in the table when the server starts but putting it within the function will make it work because at that time, the players are there.
Now this thread has been solved. Thanks to everyone who helped, I really appreciate what you guys done today.
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 18 Sep 2014 02:28 PM |
So I was right all along. I love having congratulations revoked, only to have them granted again once people realize what is up... |
|
|
| Report Abuse |
|
|