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
 

function value?

Previous Thread :: Next Thread 
fireheart568 is not online. fireheart568
Joined: 04 Jan 2009
Total Posts: 1285
25 Oct 2013 07:59 PM
function selectWeapon()
possibleWeapons = {game.Lighting.Weapons:GetChildren()}

randomizedSelection = math.random(1,#possibleWeapons)

randomizedChoice = possibleWeapons[randomizedSelection]

return randomizedChoice

end

function giveWeapon(weapon)
weaponClone = weapon:clone() --ERRORED ON THIS LINE
weaponClone.Parent = game.Players.Player1
end

--When it's bought
giveWeapon(selectWeapon)
--end

-----------------------------------------------------------
CODE END
-----------------------------------------------------------

Output says that I tried to reparent a 'function value'.

Can anybody tell me what I've done wrong?
Report Abuse
unholysoda is not online. unholysoda
Joined: 15 May 2010
Total Posts: 9024
25 Oct 2013 08:02 PM
Weapon = selectWeapon()

giveWeapon(Weapon)

http://www.roblox.com/My/Groups.aspx?gid=66545
Report Abuse
AdvancedFunctioning is not online. AdvancedFunctioning
Joined: 20 Oct 2013
Total Posts: 21
25 Oct 2013 08:11 PM
weaponclone = [item]:clone()
[item].Parent = [EX: game.Workspace]
Report Abuse
fireheart568 is not online. fireheart568
Joined: 04 Jan 2009
Total Posts: 1285
25 Oct 2013 09:38 PM
My script is now:

--------------------------------
CODE START
--------------------------------

function selectWeapon()
possibleWeapons = {game.Lighting.Weapons:GetChildren()}

randomizedSelection = math.random(1,#possibleWeapons)

randomizedChoice = possibleWeapons[randomizedSelection]

return randomizedChoice

end

function giveWeapon(weapon)
print(weapon.Name)
weaponClone = weapon:clone()
weaponClone.Parent = game.Players.Player1
end

Weapon = selectWeapon()

--When it's bought
giveWeapon(Weapon)
--end

--------------------------------
CODE END
--------------------------------


But now it prints out nil before erroring.

It's error is trying to clone a nil object...
Report Abuse
unholysoda is not online. unholysoda
Joined: 15 May 2010
Total Posts: 9024
25 Oct 2013 09:41 PM
function selectWeapon()
possibleWeapons = {game.Lighting.Weapons:GetChildren()}
randomizedSelection = math.random(1,#possibleWeapons)
randomizedChoice = possibleWeapons[randomizedSelection]
return randomizedChoice
end

function giveWeapon()
Weapon = selectWeapon()
print(Weapon)
WeaponClone = Weapon:Clone()
WeaponClone.Parent = game.Players.Player1
end

giveWeapon()

http://www.roblox.com/My/Groups.aspx?gid=66545
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