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

"2 is not a valid member of IntValue" ?

Asked by 6 years ago
Edited 6 years ago

I am trying to change the name and value of an IntValue named "2" which is a child of "Inventory" which is a child of "Dadithan" which is a child of "PlayerData". I am getting the error "2 is not a valid member of IntValue". How can I accurately reference this object? I will provide a screenshot if need. I am very new to scripting.

local Dad = game.ServerStorage.PlayerData:WaitForChild("Dadithan", 20)
local F = Dad.Inventory


function si()
    if F["2"].Value == 1 then
        F["2"].Value = 100
        F["2"].Metal.Value = 14
        F["2"].Wood.Value = 15  
        F["2"].Name = "40"
    end
end

si()

0
`F:WaitForChild('2')`? TheeDeathCaster 2368 — 6y
0
Can I get a rewritten version of it? I'm not sure what youre suggesting Dadithan -5 — 6y

1 answer

Log in to vote
0
Answered by
EB8699 30
6 years ago

Not quite sure why you have the ["2"] there, as F.2.Value should work just fine? From my knowledge you only use the brackets when you are referring to a table.

In example:

local Table = {
    ["Value"] = 1,
    ["Noogin"] = 2,
    }

print(Table["Noogin"])

That'd print "2".

But back to the script, this is what Caster was referring to:

local Dad = game.ServerStorage.PlayerData:WaitForChild("Dadithan", 20)
local F = Dad.Inventory
local Number = F:WaitForChild("2", 20)

function si()
    if Number.Value == 1 then
        Number.Value = 100
        Number.Metal.Value = 14
        Number.Wood.Value = 15  
        Number.Name = "40"
    end
end

si()

I'd suggest learning tables as that's a more secure and efficient way of doing it, however if you feel that you prefer this method then by all means.

I'll give a example of what the script would look like if it used a table: (Assuming that the "Number.Value" is representing "Money" and the Number.Name is representing "Age" as I have no idea what your doing with them).

local PlayerData = {
    ["Age"] = 0,
    ["Money"] = 0,
    ["Metal"] = 0,
    ["Wood"] = 0,
    }

local function DoCheck()
    if PlayerData["Money"] == 1 then
        PlayerData["Money"] = 100
        PlayerData["Metal"] = 14
        PlayerData["Wood"] = 15
        PlayerData["Age"] = 40
    end
end

--To add simply change the data like so, or use this function
local function AddToData(Value, Count)
    PlayerData[Value] = PlayerData[Value] + Count
end

--These two will do the same thing, but it's quicker to simply call the function
AddToData("Money", 50)
PlayerData["Money"] = PlayerData["Money"] + 50

With this method you don't have to wait for anything as it's already loaded by the time it hits the function, plus (Low level) exploiters can't simply edit the value to add to a stat.

If this is unhelpful, just let me know and I'll try to correct it.

Ad

Answer this question