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
 

Re: Why doesn't this work?

Previous Thread :: Next Thread 
SummerOrbit is not online. SummerOrbit
Joined: 21 Nov 2012
Total Posts: 28
16 Dec 2012 02:19 PM
local PlayersService = game.Players

function weaponCheck()
local character = PlayersService.localPlayer.Character:GetChildren()
for i,v in pairs(character) do
if v.ClassName == "Tool" then
return true
end
end
return false
end

PlayersService.localPlayer.Backpack.Changed:connect(function(property)
if weaponCheck() == false then
local back = PlayersService.localPlayer.Backpack:GetChildren()
print(property.Name)
back[property].Parent = PlayersService.localPlayer.Character
end
end)

It's supposed to take out a tool if you put it away and there isn't another tool out but it doesn't work.

No errors
Report Abuse
dmjoe is not online. dmjoe
Joined: 01 May 2009
Total Posts: 2387
16 Dec 2012 02:24 PM
for i,v in pairs(character):GetChilderen() do
if v.ClassName == "Tool" then

?
Report Abuse
SummerOrbit is not online. SummerOrbit
Joined: 21 Nov 2012
Total Posts: 28
16 Dec 2012 02:26 PM
What?
Report Abuse
dmjoe is not online. dmjoe
Joined: 01 May 2009
Total Posts: 2387
16 Dec 2012 02:28 PM
Okay nevermind. I'm an idiot ._.
Report Abuse
SummerOrbit is not online. SummerOrbit
Joined: 21 Nov 2012
Total Posts: 28
16 Dec 2012 02:31 PM
Lol okay :P

So I changed the function so it connects on DecendantAdded instead of Changed now and I'm getting this error:

Players.Player1.PlayerGui.KeyScript:18: attempt to index field '?' (a nil value)

Line 18 is: back[property].Parent = PlayersService.localPlayer.Character
Report Abuse
jelly134 is not online. jelly134
Joined: 25 Aug 2008
Total Posts: 1137
16 Dec 2012 02:32 PM
local PlayersService = game.Players

function weaponCheck()
local character = PlayersService.LocalPlayer.Character:GetChildren()
for i,v in pairs(character) do
if v.ClassName == "Tool" then
return true
end
end
return false
end

PlayersService.LocalPlayer.Backpack.Changed:connect(function(property)
if weaponCheck() == false then
local back = PlayersService.LocalPlayer.Backpack:GetChildren()
print(property.Name)
back[property].Parent = PlayersService.LocalPlayer.Character
end
end)

--Make sure this is in a local script inside the player or the character of the player.
Report Abuse
jelly134 is not online. jelly134
Joined: 25 Aug 2008
Total Posts: 1137
16 Dec 2012 02:33 PM
What do you want it to do? Ignore my script for now.
Report Abuse
SummerOrbit is not online. SummerOrbit
Joined: 21 Nov 2012
Total Posts: 28
16 Dec 2012 02:39 PM
It's supposed to take out a tool if you put it away and there isn't another tool out but it doesn't work.
Report Abuse
SummerOrbit is not online. SummerOrbit
Joined: 21 Nov 2012
Total Posts: 28
16 Dec 2012 03:02 PM
Help please.
Report Abuse
jelly134 is not online. jelly134
Joined: 25 Aug 2008
Total Posts: 1137
16 Dec 2012 03:11 PM
What do you mean "out" ? do you mean selected or what?
Report Abuse
SummerOrbit is not online. SummerOrbit
Joined: 21 Nov 2012
Total Posts: 28
16 Dec 2012 03:20 PM
"It's supposed to take out a tool if you put it away and there isn't another tool out but it doesn't work."

Out = Put in their character

Put away = deselected/placed into backpack

Isn't another tool out = There isn't a tool in their character

It doesn't work = It doesn't do the above things
Report Abuse
jelly134 is not online. jelly134
Joined: 25 Aug 2008
Total Posts: 1137
16 Dec 2012 03:44 PM
function weaponCheck()
character = game.Players.LocalPlayer.Character:GetChildren()
for i,v in pairs(character) do
if v.ClassName == "Tool" then
return true
break
end
end
return false
end

PlayersService.LocalPlayer.Backpack.ChildAdded:connect(function(child)
if child.ClassName == "Tool" and weaponCheck() == false then
local back = game.Players.LocalPlayer.Backpack:GetChildren()
child.Parent = game.Players.LocalPlayer.Character
end
end)

--give that a try
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