|
| 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
|
  |
| 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 |
|
|
|
| 07 Aug 2016 10:06 PM |
| So how do I get it to give it to the player? |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 07 Aug 2016 10:48 PM |
| "Workspace.Part.Script:3: attempt to index a nil value" its not working |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| Joined: 02 Jul 2012 |
| Total Posts: 118 |
|
|
| 08 Aug 2016 01:46 AM |
| newtool.Parent = game.Players[hit.Parent.Name].Backpack |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2016 01:58 AM |
| My function works better because it detects hats and attachments. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|