[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