Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Player is a nil Value?

Asked by 6 years ago

I'm making a game that has a cash IntValue in it and it says that Players.CreeperAssassin005.Backpack.RustyShovel.Script:13: attempt to index local 'player' (a nil value). Any help?

script.Parent.blade.Touched:connect(function(hit)

if script.Parent.CanDamage.Value == true then

script.Parent.CanDamage.Value = false

hit.Parent.Humanoid:TakeDamage(20)

if hit.Parent.Humanoid.Health == 0 then
local  humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid ~= nil then
      local player = game.Players:GetPlayerFromCharacter(hit.Parent)
      local money = player.leaderstats.Cash
      money.Value = money.Value + 999999
end
end
end
end)

3 answers

Log in to vote
0
Answered by 6 years ago

try this

script.Parent.blade.Touched:connect(function(hit)

if script.Parent.CanDamage.Value == true then

script.Parent.CanDamage.Value = false

hit.Parent.Humanoid:TakeDamage(20)

if hit.Parent.Humanoid.Health == 0 then
local  humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid ~= nil then
if player ~= nil then
      local player = game.Players:GetPlayerFromCharacter(hit.Parent)
      local money = player.leaderstats.Cash
      money.Value = money.Value + 999999
end
end
end
end
end)
0
It doesn't have any error messages but it doesn't give my the money... CreeperAssassin005 30 — 6y
0
Using Print I figured out that the code stops at if player ~= nil then, so this code doesn't work in this state. CreeperAssassin005 30 — 6y
0
Line 12 has to go after line 13... TheeDeathCaster 2368 — 6y
0
^already tried that CreeperAssassin005 30 — 6y
Ad
Log in to vote
0
Answered by
GingeyLol 338 Moderation Voter
6 years ago
Edited 6 years ago
script.Parent.blade.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
        if script.Parent.CanDamage.Value == true then
              local player = game.Players:GetPlayerFromCharacter(hit.Parent)
              local money = player:WaitForChild(“leaderstats”).Cash
                script.Parent.CanDamage.Value = false
                hit.Parent.Humanoid:TakeDamage(20)
                    money.Value = money.Value + 999999
        end
    end
end)
0
Doesn't even do damage now :/ CreeperAssassin005 30 — 6y
0
try it now my boi GingeyLol 338 — 6y
0
nope :/ CreeperAssassin005 30 — 6y
0
hm GingeyLol 338 — 6y
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
script.Parent.blade.Touched:connect(function(hit)
    if script.Parent.CanDamage.Value == true then
        script.Parent.CanDamage.Value = false
        if hit.Parent:findFirstChild("Humanoid") then hit.Parent.Humanoid:TakeDamage(20) end
        if hit.Parent.Humanoid.Health == 0 then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if player then
                local money = player.leaderstats.Cash
                money.Value = money.Value + 999999
            end
        end
    end
end)

And if that doesn't work, there is probably something wrong with your tool. Try debugging it before saying it doesn't work. Use print() and warn().

Answer this question