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: Backpack is not a valid member of part?

Previous Thread :: Next Thread 
breifmanny is not online. breifmanny
Joined: 23 Dec 2011
Total Posts: 341
07 Aug 2016 10:03 PM
Duh, I know that.. But my script is supposed to send a random item to your inventory... But it does not...

chest = script.Parent
items = {1, 2}
sword = game.Lighting.ClassicSword
gun = game.Lighting.ClassicPaintballGun
deb = false

function onTouch(hit)
if deb == false then
deb = true
if deb == true then
local enter = math.random(1, #items)
if enter == 1 then
sword.Parent = hit.Backpack
else if enter == 2 then
gun.Parent = hit.Backpack
chest:Destroy()
end
end
end
end
end
script.Parent.Touched:connect(onTouch)


It comes up in output when I touch it as "Backpack is not a valid member of part". How would I get it to send the item into the players who touches it's backpack?
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
07 Aug 2016 10:04 PM
Players don't touch parts, parts touch parts. The "hit" parameter is the part that touched it.
Report Abuse
breifmanny is not online. breifmanny
Joined: 23 Dec 2011
Total Posts: 341
07 Aug 2016 10:06 PM
So how do I get it to give it to the player?
Report Abuse
pidgey is not online. pidgey
Joined: 16 Jan 2008
Total Posts: 2739
07 Aug 2016 10:10 PM
"sword.Parent = hit.Backpack"

Touched argument #1 returns the part which touched it, and since the player carries the backpack, search for the player

ex:
Touched:connect(function(onTouch)
if onTouch.Parent:IsA("Model") and game.Players:FindFirstChild(onTouch.Parent.Name) --checks if onTouch's parent is a model, then checks if the model is a player
local inventory = game.Players:GetPlayerFromCharacter(script.Parent).Backpack
sword.Parent = inventory
end
end)


https://www.roblox.com/My/Groups.aspx?gid=2893266 | pidgey is my name sh##posting is my game
Report Abuse
breifmanny is not online. breifmanny
Joined: 23 Dec 2011
Total Posts: 341
07 Aug 2016 10:48 PM
"Workspace.Part.Script:3: attempt to index a nil value" its not working
Report Abuse
Quebankus is not online. Quebankus
Joined: 25 Aug 2011
Total Posts: 846
08 Aug 2016 12:12 AM
https://forum.roblox.com/Forum/ShowForumGroup.aspx?ForumGroupID=9

"This is the place for discussion about scripting. Anything about scripting that is not a help request or topic belongs here."
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
08 Aug 2016 01:34 AM
if you hit something then that means your character has hit something

function IsPlayer(h)

for _,v in pairs(game.Players:GetPlayers()) do

if v.Character and h:IsDescendantOf(v.Character) then
return v
end

end
return nil
end


if you use IsPlayer(hit) then it will return their player (or nil if they dont have one)
Report Abuse
Marienus is not online. Marienus
Joined: 02 Jul 2012
Total Posts: 118
08 Aug 2016 01:46 AM
newtool.Parent = game.Players[hit.Parent.Name].Backpack
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
08 Aug 2016 01:58 AM
My function works better because it detects hats and attachments.
Report Abuse
Milenveliki is not online. Milenveliki
Joined: 14 Aug 2013
Total Posts: 1097
08 Aug 2016 02:22 AM
chest = script.Parent
items = {1, 2}
sword = game.Lighting.ClassicSword
gun = game.Lighting.ClassicPaintballGun
deb = false

function onTouch(hit)
wait""if game.Players:FindFirstChild(hit.Parent.Name) then
if deb == false then
deb = true
if deb == true then
local enter = math.random(1, #items)
if enter == 1 then
sword.Parent = game.Players:FindFirstChild(hit.Parent.Name).Backpack
else if enter == 2 then
gun.Parent = game.Players:FindFirstChild(hit.Parent.Name).Backpack
chest:Destroy()
end;end
end
end
end
end
script.Parent.Touched:connect(onTouch)
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