|
| 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 |
|
|
|
| 06 Jan 2016 05:31 PM |
| Line 39, what's part.Parent, I think you mean hit.Parent. |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2016 05:31 PM |
Whoops, screwed up there. It is actually function onTouched(part)
|
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 06 Jan 2016 05:34 PM |
Also I think WaitForChild would be better for getting the leaderstats.
|
|
|
| Report Abuse |
|
|
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 |
|
|
| |
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 06 Jan 2016 05:47 PM |
Where is this sword an head coming from? I don't see it in the script. |
|
|
| Report Abuse |
|
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 06 Jan 2016 06:43 PM |
Just do this, instead of defining the useless variable "person": game.Players:GetPlayerFromCharacter(part.Parent)
|
|
|
| Report Abuse |
|
|
| |
|