generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Value in table not being detected correctly?

Previous Thread :: Next Thread 
imnota10 is not online. imnota10
Joined: 25 Dec 2010
Total Posts: 2594
26 May 2013 03:08 PM
Before anyone even attempts to, I DO NOT want a "fixed" version of the script, what I want is to know WHY THE SCRIPT ISN'T WORKING. If you post a fixed version, I will ignore it. Do not bother doing so.

Here is the script:

---------------------------------------------------------------------------------

math.randomseed(tick()) -- [makes sure that math.random isn't the same each time a new server starts.]

GUIText = script.Parent.BillboardGui.Frame.NameText.Text -- [Variable to the text in a GUI.]

PlayerTable = {} --[Table where players names will be held and where the GUI will get the names to make its text as.]




game.Players.PlayerAdded:connect(function(player)

c = game.Players.NumPlayers -- [Variable containing the amount of players after the last person who joined the server.]

PlayerTable[c] = player.Name -- [Setting "PlayerTable"s value at "c" to the name of the last player to join]

if (GUIText == "0") then

print("Changing")

GUIText = PlayerTable[c] -- [Sets the GUI's text to the name of the last player to join]

elseif (GUIText ~= "0") then

print("Continue")

end
end)



game.Players.PlayerRemoving:connect(function(player)

c = game.Players.NumPlayers -- [Variable containing the amount of players after the last person who left the server.]

if(GUIText == player.Name) then

table.remove(PlayerTable, player.Name) -- [removes the player who left from "PlayerTable" (I'm sure this doesn't work, however this doesn't affect the current problem)]

GUIText = PlayerTable[math.random(c)] -- [Sets the GUI's text to a new players name, randomly selected from the table of names.]

elseif(GUIText ~= player.Name) then

table.remove(PlayerTable, player.Name) -- [removes the player who left from "PlayerTable"]

end
end)

---------------------------------------------------------------------------------

Here's the part I THINK it's messing up on:

---------------------------------------------------------------------------------

game.Players.PlayerAdded:connect(function(player)
c = game.Players.NumPlayers
PlayerTable[c] = player.Name
if (GUIText == "0") then
print("Changing")
GUIText = PlayerTable[c]

---------------------------------------------------------------------------------

Information:

- There are no error messages in the "output window"

- "GUIText = script.Parent.BillboardGui.Frame.NameText.Text" is simply making a variable pointing to the text in a GUI, which is pre-set as "0", because of the check during the function shown above.

- The purpose of the script is to set the GUI text mentioned above to a random players name on the server, the problem is that it SHOULD be setting the text to the first player to join the server, however the text remains as "0", otherwise, the GUI has no importance, and is the same as any other GUI you can think of, the tree is already mentioned inside the script so there is nothing else to mention or show about this GUI.

- I have tested multiple times to see if the table is properly receiving the value it is meant to be given, and yes, it is. Every time I've tested, the table will always have the value "imnota10", but whenever I try to give the GUI text this value, it won't work.

- There is nothing more to this script, there is nothing else accessing this script, there are a few unrelated scripts accessing this model that have to do with the model disappearing when touched, however I have tried with these scripts both enabled and disabled, and this script still acts the exact same way.

- If there is anything else you need to know, don't hesitate to ask.

---------------------------------------------------------------------------------

And once again, I cannot stress enough... DO NOT FIX THIS, HELP ME UNDERSTAND WHAT IS WRONG.
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
26 May 2013 03:53 PM
Set
GUIText = script.Parent.BillboardGui.Frame.NameText.Text
to
GUIText = script.Parent.BillboardGui.Frame.NameText

because when you include the .Text at the end, changing the variable no longer changes the actual value, therefore every time you need to change the Text now, you will need to do
GUIText.Text = "text"
Report Abuse
imnota10 is not online. imnota10
Joined: 25 Dec 2010
Total Posts: 2594
26 May 2013 04:01 PM
Nothing changed. Upon entering the server, the GUI's text remains as "0" rather than changing to my name.
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
26 May 2013 04:41 PM
Show me the new script just in case you made any errors. It's always good to have a fresh set of eyes.
Report Abuse
imnota10 is not online. imnota10
Joined: 25 Dec 2010
Total Posts: 2594
26 May 2013 04:53 PM
math.randomseed(tick())
GUIText = script.Parent.BillboardGui.Frame.NameText
PlayerTable = {}

game.Players.PlayerAdded:connect(function(player)
c = game.Players.NumPlayers
PlayerTable[c] = player.Name
if (GUIText == "0") then
print("Changing")
GUIText = PlayerTable[c]

elseif (GUIText ~= "0") then
print("Continue")
end
end)

game.Players.PlayerRemoving:connect(function(player)
c = game.Players.NumPlayers
if(GUIText == player.Name) then
table.remove(PlayerTable, player.Name)
GUIText = PlayerTable[math.random(c)]

elseif(GUIText ~= player.Name) then
table.remove(PlayerTable, player.Name)
end
end)
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
26 May 2013 05:40 PM
Read my post again:
"therefore every time you need to change the Text now, you will need to do
GUIText.Text = "text""
Report Abuse
imnota10 is not online. imnota10
Joined: 25 Dec 2010
Total Posts: 2594
26 May 2013 06:19 PM
I still don't get why if I add .Text to it, it doesn't work...
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
26 May 2013 06:50 PM
Because the variable simply stores the value and nothing else, so changing the variable will change the value, but it won't achieve the effect you want.
Omitting the .Text makes the variable store that path, and so you can easily manipulate .Text now.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image