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

[Solved] Not a valid member of player error?

Asked by 5 years ago
Edited 5 years ago
local name = script.Name

gun=game:GetService("DataStoreService"):GetDataStore(name)

function SaveGun(player)
    gun:SetAsync(player.userId, player.gunloadout.GunName.equippedGun.Value)
    print("Owned guns saved!")
end

function LoadGun(player)
    local Gunny = gun:getAsync(player.userId)

    if gun ~= nil then
        player.gunloadout.GunName.equippedGun.Value = Gunny -- Error happens here, it does not take "gunloadout" as a valid member

    end
end

function onPlayerEntered(newPlayer)

        if newPlayer:FindFirstChild("GunsSavingData") == nil then
            local folder = Instance.new("Folder")
            folder.Name = "GunsSavingData"
            folder.Parent = newPlayer
        end

        gunloadout = newPlayer:WaitForChild("GunsSavingData") -- Gunloadout

        local GunName = Instance.new("Folder", gunloadout)
        GunName.Name = name

        local equippedGun = Instance.new("IntValue", gunloadout)
        equippedGun.Name = "HasValue"
        equippedGun.Value = "1"

        local children = script:GetChildren()

        for i = 1,#children do
            local c = children[i]:clone()
            c.Parent = GunName
        end

        GunName.Parent = gunloadout
        equippedGun.Parent = GunName
        gunloadout.Parent = newPlayer

        newPlayer:WaitForDataReady() 

        LoadGun(newPlayer)
end 

function onPlayerRemoving(player)
    print("Attempting to save score for " .. player.Name)
    SaveGun(player)
end
0
are you sure that gunloadout's parent is the player? mixgingengerina10 223 — 5y
0
In local server test, it shows as it is https://gyazo.com/d5472c982666bb058a30e83294ac5984 Lamantinel -1 — 5y
0
Can I see the whole player tree? mixgingengerina10 223 — 5y
View all comments (4 more)
0
It should be player.GunsSavingData OOF mixgingengerina10 223 — 5y
0
It made an error bcs you defined gunsloadout after you used it.... mixgingengerina10 223 — 5y
0
Oh man, now I feel stupid. Thanks for helping me! Lamantinel -1 — 5y
0
add [SOLVED] in the title mixgingengerina10 223 — 5y

Answer this question