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 » Scripters
Home Search
 

Re: Tables

Previous Thread :: Next Thread 
Romul is not online. Romul
Joined: 08 Mar 2009
Total Posts: 597
18 Aug 2015 06:06 PM
The following function seems to not be working if all players in the server are not in the table. I haven't had this issue before, so it is strange as to why it is breaking now. Everything access a Players table:

Players = {}

function Murderer()
local pick = math.random(1, #Players)
local MPicked = Players[pick]
MPicked.Backpack:findFirstChild("TMS").Value = "Murder"
game.ServerStorage.GameContents.MadSpy.MurderDead:clone().Parent = MPicked.Backpack
MPicked.Backpack.MurderDead.Disabled = false
table.remove(Players, pick)
end

The third line, where it is changing the value is the line breaking. Its not the value issue because the values are in the players. Here is the error it's giving:

18:03:39.640 - ServerScriptService.MasterScript:141: attempt to index a nil value
18:03:39.658 - Stack Begin
18:03:39.660 - Script 'ServerScriptService.MasterScript', Line 141 - global Murderer
18:03:39.661 - Script 'ServerScriptService.MasterScript', Line 183
18:03:39.662 - Stack End
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
18 Aug 2015 06:13 PM
function stopMakingAMurderGame()
local player = game.Players:GetPlayers()
local ranPlayer = players[math.random(1,#player)]
print(ranPlayer.." is the murderer")
return ranPlayer
end

function turnIntoMurderer(plr)
plr:WaitForChild("Murderer").Value = true
plr.Backpack:WaitForChild("MurderDead").Disabled = false
end

local player = stopMakingAMurderGame()

turnIntoMurderer(player)
Report Abuse
Romul is not online. Romul
Joined: 08 Mar 2009
Total Posts: 597
18 Aug 2015 06:15 PM
1) Why was the script breaking on that line? What was the issue?

2) I'm not making a murder game. I'm making a set of mini games and have a murder knockoff mode for the fun.
Report Abuse
Romul is not online. Romul
Joined: 08 Mar 2009
Total Posts: 597
18 Aug 2015 06:18 PM
Also that wouldn't work. You are sourcing up the players ingame, I'm sourcing up from a table I have made with players loaded into it.
Report Abuse
Romul is not online. Romul
Joined: 08 Mar 2009
Total Posts: 597
18 Aug 2015 06:48 PM
Could the error be it trying to access the Players section too quickly? Wouldn't explain how it works if all players in the server are in the Lobby working vs. one player sitting in the Spawning category and it breaking.
Report Abuse
Romul is not online. Romul
Joined: 08 Mar 2009
Total Posts: 597
18 Aug 2015 07:13 PM
I'm puzzled at how this is a hit or miss function..
Report Abuse
Romul is not online. Romul
Joined: 08 Mar 2009
Total Posts: 597
18 Aug 2015 07:57 PM
I hate to be this pushy, but Bump 1.
Report Abuse
FrankieTheDino is not online. FrankieTheDino
Joined: 27 Jul 2008
Total Posts: 603
18 Aug 2015 07:59 PM
Is it possible you can number the script so we can see what line it is actually on?


Thanks!
Report Abuse
BluesteelBoyz is not online. BluesteelBoyz
Joined: 15 Feb 2012
Total Posts: 1841
18 Aug 2015 07:59 PM
wow...bumping when you made like 2 seconds ago...

Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
18 Aug 2015 08:04 PM
@Romul This was breaking:
MPicked.Backpack:findFirstChild("TMS").Value = "Murder"

because FindFirstChild merely looks for things, but does not wait for them.
If "TMS" is not created on time (or just doesn't exist) that line is equivalent to:
(nil).Value = "Murder"

For things like that people generally like to use :WaitForChild() as it looks for, and if need be waits, for the named child to exist.
Report Abuse
Romul is not online. Romul
Joined: 08 Mar 2009
Total Posts: 597
18 Aug 2015 08:06 PM
Frankie, I stated in the second paragraph that it is the third line of the function giving the error I posted.

Bluesteel, get out of the Scripting forum. You've done enough damage for one day. I posted almost an hour before bumping it. Not 2 seconds ago. How about you start working on your game and maybe even take some help from these forum posts. I'm currently making a REAL minigame and these are the kind of scripts you NEED to be learning.

KTHXBAI
Report Abuse
Romul is not online. Romul
Joined: 08 Mar 2009
Total Posts: 597
18 Aug 2015 08:07 PM
Casualist, I understand that, however I'm 100% sure the value is there. It isn't giving an error for the missing object, just an issue with what was stated in the Logs. Also, the fact that it works if every player in the game is in the Lobby versus just a few and some staying in the Spawning team, just puzzles me.

I definitely will look into WaitForChild, that seems like it would run better, just not the issue in this statement I don't think.
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
18 Aug 2015 08:10 PM
@Romul Could you take it from the top and walk me through the issue as it presently stands? i.e. conditions wherein the issue appears, how it's supposed to work, relevent code+logs
Report Abuse
Romul is not online. Romul
Joined: 08 Mar 2009
Total Posts: 597
18 Aug 2015 08:15 PM
I can't even begin to start at the top with this massive script. I'll throw it in some simple terms to get the gist along the way.

Players = {}

The game has a function that adds players with the Lobby team's TeamColor to the Players table as shown above.

The game then gives players the TMS value within their Backpacks as it only needs to be temporary as they are alive.

The game then goes to select the roles of each player. First being the Murderer, second being the Security, third distributing the rest as Bystanders. Now if this function below is breaking as I stated, then the Security and Bystander functions are also breaking. It is breaking on the spot with the asterisks.

function Murderer()
local pick = math.random(1, #Players)
local MPicked = Players[pick]
*******MPicked.Backpack:findFirstChild("TMS").Value = "Murder"
game.ServerStorage.GameContents.MadSpy.MurderDead:clone().Parent = MPicked.Backpack
MPicked.Backpack.MurderDead.Disabled = false
table.remove(Players, pick)
end

18:03:39.640 - ServerScriptService.MasterScript:141: attempt to index a nil value

It's indicating that the line with the asterisks is attempting to index a nil value.
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
18 Aug 2015 08:20 PM
@Romul
I've already explained that, the issue is that TMS does not exist when you call Murderer()

FindFirstChild() returns a child with a specified name if it exists, otherwise it returns nil
Ergo, the following code:
MPicked.Backpack:findFirstChild("TMS").Value = "Murder"

Reads like this when it errors:
(nil).Value = "Murder"
because FindFirstChil() could not find TMS.

Fault either lies with the code that creates TMS or you are looking for it before it has time to be replicated (actually created client-side).

A solution would be to use :WaitForChild("TMS").Value = "Murder"
but it may just obscure the issue and cause your code to hang if there TMS is not actually being created//parented correctly.
Report Abuse
Romul is not online. Romul
Joined: 08 Mar 2009
Total Posts: 597
18 Aug 2015 08:22 PM
I get what you are saying and I will change it to WaitForChild to hopefully resolve it. I'm just puzzled as to why it would do so in certain situations. It was probably just a coincidental hit or miss. I have never really had this issue before either so I was puzzled as to why it was doing it now. Maybe before I was just lucky it had loaded in time.

I'll let you know if the problem occurs again. Thanks!
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
18 Aug 2015 08:27 PM
@Romul "coincidental hit or miss" implies that you lucked out and it loaded on time, if you always have/had this error then it would be indicative that the fault lies with TMS creation code. Based on the description of your error :WaitForChild() should fix it.

Since you are new to using WaitForChild just be wary it will hang if the child is never created. Also, it's good practice to name said child before it gets parented (parenting followed by naming might cause WaitForChild to be blind to it and cause your code to hang).
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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