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: what is this nonsense?

Previous Thread :: Next Thread 
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 05:26 PM
This is in a function onTouched(hit)

39: local person = part.Parent
40: local player = game.Players:GetPlayerFromCharacter(person)
41: local stats = player.leaderstats:FindFirstChild(currency)

Output keeps saying:

18:24:42.909 - Workspace.Sword.Head.Give:41: attempt to index local 'player' (a nil value)
18:24:42.910 - Stack Begin
18:24:42.910 - Script 'Workspace.Sword.Head.Give', Line 41
18:24:42.910 - Stack End
Report Abuse
benthanh123 is not online. benthanh123
Joined: 27 May 2010
Total Posts: 567
06 Jan 2016 05:31 PM
Line 39, what's part.Parent, I think you mean hit.Parent.
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 05:31 PM
Whoops, screwed up there. It is actually function onTouched(part)
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 05:34 PM
bump (I mean in the script it actually is part, i just screwed up when writing the start)
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
06 Jan 2016 05:34 PM
Also I think WaitForChild would be better for getting the leaderstats.
Report Abuse
nox7 is not online. nox7
Joined: 29 Aug 2008
Total Posts: 27467
06 Jan 2016 05:35 PM
Other things can touch the object. Check:

if (player) then
-- do stuff
end
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 05:37 PM
Still isn't working.
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 05:38 PM
The script already has something like that near the start:

if (part.Parent:FindFirstChild("Humanoid") ~= nil) then
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 05:45 PM
Bump
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
06 Jan 2016 05:47 PM
local currency
if game.Players:FindFirstChild(part.Parent.Name) and game.Players[part.Parent.Name]:FindFirstChild('leaderstats') and game.Players[part.Parent.Name].leaderstats:FindFirstChild('currency') then
currency = game.Players[part.Parent.Name].leaderstats.currency
end
if currency then
--do what you want to do here to currency
end
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
06 Jan 2016 05:47 PM
Where is this sword an head coming from?
I don't see it in the script.
Report Abuse
Kie413Games is not online. Kie413Games
Joined: 06 May 2010
Total Posts: 3896
06 Jan 2016 05:49 PM
My bad it's the name lol.
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 05:51 PM
The currency is already set. It's an INT value in a configurations folder called Settings.

local opt = script.Parent.Parent.Settings
local currency = opt.Currency.Value
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
06 Jan 2016 05:53 PM
According to that script you just showed me, the currency is in something called settings, not inside of something called leaderstats. Your leaderboard is not set up the same way that this script is trying to find currency at.
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 05:58 PM
No, currency is an INT value. The script is supposed to go into the leaderstats and find the child which has the same name as currency's value.
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 06:06 PM
bump
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
06 Jan 2016 06:07 PM
You just solve one issue then... change line 41 to this

local stats = player.leaderstats:FindFirstChild(currency.Value)


The other issue is the error:

"attempt to index local 'player' (a nil value)"

Line 40 is not finding the player in game.Players, meaning that you are not finding the character on line 39:

local person = part.Parent

Something with this line is not working the way you want it to... You should use the print function to find where the problem starts. I would do this:

local person = part.Parent
print(person.Name) <-- should return the name of the character
local player = game.Players:FindFirstChild(person)
print(player) <-- should return either nil or the player's name
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
06 Jan 2016 06:09 PM
Nvm, forget that first comment, didn't see that you set currency as the value of currency, lol. However you still need to use the print function to see where the script is going wrong...
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 06:18 PM
I've taken your ideas into consideration, but still does not work. I'll just give you the first half of the script (where the problems are)

local opt = script.Parent.Parent.Settings
local cost = opt.Cost.Value
local currency = opt.Currency.Value
local effectcash = opt.EffectCash.Value

function onTouched(part)
if (part.Parent:FindFirstChild("Humanoid") ~= nil) then
if (part.Parent:FindFirstChild("Sword") == nil) then
local person = part.Parent
local player = game.Players:GetPlayerFromCharacter(person)
if gamepass ~= true and playerspecific ~= true then
local stats = player.leaderstats[currency]
if effectcash then
stats.Value = stats.Value - cost
end
local toolclone = script.Parent.Parent.Sword:clone()
toolclone.Handle.Anchored = false
toolclone.Parent = person
else
person.Humanoid.Health = 0
end
end
end
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 06:25 PM
bump
Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 06:35 PM
bump
Report Abuse
AdvancedObjects is not online. AdvancedObjects
Joined: 11 Dec 2012
Total Posts: 3354
06 Jan 2016 06:38 PM
The code you posted:
1.) Your forgetting an end.
2.) "part.Parent:FindFirstChild("Humanoid") ~= nil" "~= nil" is unnecessary.
3.) "gamepass" & "playerspecific" haven't been defined anywhere.



Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 06:41 PM
1.) No i'm not
2.) didn't help
3.) I left that part out when pasting

May i remind you that the problem is: attempt to index local 'player' (a nil value)
Report Abuse
AdvancedObjects is not online. AdvancedObjects
Joined: 11 Dec 2012
Total Posts: 3354
06 Jan 2016 06:43 PM
Just do this, instead of defining the useless variable "person":
game.Players:GetPlayerFromCharacter(part.Parent)



Report Abuse
aaront2000 is not online. aaront2000
Joined: 27 Oct 2009
Total Posts: 189
06 Jan 2016 06:47 PM
Didn't help :\
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