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: nil Value

Previous Thread :: Next Thread 
Torush1 is online. Torush1
Joined: 04 Feb 2011
Total Posts: 47
15 Jan 2016 09:45 PM
Script:

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

local PlayerFolders = game.Workspace.Players
local RedTeam = PlayerFolders.Red
local BlueTeam = PlayerFolders.Blue
local Neutral = PlayerFolders.Neutral

local Humanoid = character:FindFirstChild("Humanoid")
Humanoid.JumpPower = 0

local PlayerModel = game.Workspace:FindFirstChild(character.Name)
PlayerModel.Parent = Neutral
end)
end)

Output Problem:
13:39:35.675 - ServerScriptService.Script:36: attempt to index local 'PlayerModel' (a nil value)
13:39:35.676 - Stack Begin
13:39:35.676 - Script 'ServerScriptService.Script', Line 36
13:39:35.676 - Stack End


Can anyone please find a way to fix this please? Cheers.
Report Abuse
sayhisam1 is not online. sayhisam1
Joined: 25 Nov 2009
Total Posts: 2092
15 Jan 2016 09:52 PM
There is no playermodel that exists for the given character. You should add an if statement that checks if the PlayerModel exists


local PlayerModel = game.Workspace:FindFirstChild(character.Name)
if PlayerModel then
PlayerModel.Parent = Neutral
end

Report Abuse
Torush1 is online. Torush1
Joined: 04 Feb 2011
Total Posts: 47
15 Jan 2016 09:55 PM
The 'if' statement is false. Any other way I can localise game.Workspace.Player1 ?
Report Abuse
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
15 Jan 2016 09:59 PM
local PlayerModel = character

playermodel was already defined as character


Report Abuse
Torush1 is online. Torush1
Joined: 04 Feb 2011
Total Posts: 47
15 Jan 2016 10:02 PM
It's localising the same model, ergo doesn't make a difference.
Report Abuse
Torush1 is online. Torush1
Joined: 04 Feb 2011
Total Posts: 47
15 Jan 2016 10:17 PM
So this bit has been added to the end of the script:

if PlayerModel ~= nil then
print("Working")
PlayerModel.Parent = Neutral
end

__________

The message prints but the Player1 model isn't relocated. Player1 has been defined as PlayerModel. Is it even possible for the Player1 model to be relocated to have a different parent?
Report Abuse
Torush1 is online. Torush1
Joined: 04 Feb 2011
Total Posts: 47
15 Jan 2016 10:33 PM
I've decided to make an Instance.new script to insert a StringValue into the "Neutral" model. Thanks for the help guys. Cheers.
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