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

"Armor" leaderstat not a valid member of IntValue?

Asked by
lomo0987 250 Moderation Voter
10 years ago
wait(10)
print("Starting!")

repeat wait()until game.Players.LocalPlayer
print("Found Player")

plr=game:service("Players").LocalPlayer
print("Player has been set")

repeat wait()until plr:FindFirstChild("leaderstats")
print("Found Leaderstats")

repeat wait()until plr.Character~=nil 
print("Player has been found")

ar=plr.leaderstats:FindFirstChild("Armor")
print("Found Armor")

pl=plr.Character:FindFirstChild("Humanoid")
print("Found Humanoid")

if ar~=nil then 
    print("Starting to change health")

    pl.MaxHealth=plr.leaderstats.Armor + 100
    print("MaxHealth has been changed!")

    pl.Health=pl.Character.MaxHealth
    print("Health has been changed!")

elseif not plr2~=nil or not plr:FindFirstChild("leaderstats")~=nil or not plr:FindFirstChild("leaderstats"):FindFirstChild("Armor")~=nil then
print("Humanoid does not exist")
end

Edit: it now says that line 25 is erroring.

I have a script, what it does is finds the leaderstat 'Armor' replaces the persons max health and current health (+100) to their health. and max health.

The output says at line 6, that "Armor" isn't a valid member of IntValue.

And if anyone is wondering.. Here is the DataSave that I use to create the leaderstats...

function DataHandler(p,o,key)   
    local types = {
        IntValue = "Number";
        NumberValue = "Number";
        ObjectValue = "Instance";
        BoolValue = "Boolean";
        StringValue="String";
    }
    local t = types[o.ClassName]
    if (not t) then return end
    key = (type(key) == "string" and key or o.Name) 
    key = (#key > 0 and key or key.Name == o.Name and o.ClassName or o.Name)    
    if (not p.DataReady) then               
        p:WaitForDataReady()                                                        
    end                                                                         
    local Save,Load = p[("Save%s"):format(t)],p[("Load%s"):format(t)]   
    o.Value = Load(p,key)   
    local lastV = o.Value
    o.Changed:connect(function(v)
        lastV = v
        Delay(1,function()                      
            if (lastV ~= v) then return end 
            Save(p,key,v)
        end)
    end)
end


game.Players.PlayerAdded:connect(function(player)
    local l = Instance.new("IntValue",player)
    l.Name = "leaderstats"

    local money = Instance.new("IntValue",l)
    money.Name = "KOs"
    DataHandler(player,money,"TheMoney")

    local cashmoney = Instance.new("IntValue",l)
    cashmoney.Name = "Wipeouts"
    DataHandler(player,cashmoney,"ThePoints")

    local mh = Instance.new("IntValue",l)
    mh.Name = "Armor"
    DataHandler(player,mh,"MaxHealths")
end)

1 answer

Log in to vote
0
Answered by
wazap 100
10 years ago

local scripts sometimes load before all the information gets sent to the client

So do

repeat wait() until plr:findFirstChild"leaderstats" and plr.leaderstats:findFirstChild"Armor"

and you should be fine

0
I edited the script around.. and trying to fix some things.. and now it says this:  "attempt to perform arithmetic on field 'Armor' (a userdata value)" This is on line 25. I will update the script on top to show what i have it set as now. lomo0987 250 — 10y
Ad

Answer this question