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

[SOLVED] ownsLog doesn't exist in Players.Deadlox85854868?

Asked by 3 years ago
Edited 3 years ago

I'm trying to make a data store with tools, I've been trying to figure it out, changed to WaitForChild, or .Parent waitforchild, all of those. But sometimes it prints("Didn't Receive Tool"

Error Code:

23:11:46.727 ownsLog is not a valid member of Player "Players.Deadlox85854868" - Server - Datastores:117

Code that failed: game.Players.PlayerAdded:Connect(function(player) if player.ownsLog.Value == true then game.ServerStorage.Inventory.Log:Clone(player:WaitForChild("Backpack")) print('Gave Tool') else print("Didn't Recieve Tool") end end)

Entire Code:

local datastoreservice = game:GetService('DataStoreService')
local datastore = datastoreservice:GetDataStore('test')


game.Players.PlayerAdded:Connect(function(player)
    local TreesData
    local success, errorMsg = pcall(function()
        TreesData = datastore:GetAsync(player.UserId..' -Trees')
    end)
    if success then
        player.leaderstats.Trees.Value = TreesData
    else
        warn(errorMsg)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errorMsg = pcall(function()
        datastore:SetAsync(player.UserId..' -Trees', player.leaderstats.Trees.Value)
    end)
    if success then
        print('Saved Data!')
    else
        warn(errorMsg)
    end
end)
game.Players.PlayerAdded:Connect(function(player)
    local MoneyData
    local success, errorMsg = pcall(function()
        MoneyData = datastore:GetAsync(player.UserId..' -Money')
    end)
    if success then
        player.leaderstats.Money.Value = MoneyData
    else
        warn(errorMsg)
    end
end)
game.Players.PlayerRemoving:Connect(function(player)
    local success, errorMsg = pcall(function()
        datastore:SetAsync(player.UserId..' -Money', player.leaderstats.Money.Value)
    end)
    if success then
        print('Saved Data!')
    else
        warn(errorMsg)
    end
end)
game.Players.PlayerAdded:Connect(function(player)
    local LeafsData
    local success, errorMsg = pcall(function()
        LeafsData = datastore:GetAsync(player.UserId..' -Leafs')
    end)
    if success then
        player.leaderstats.Leafs.Value = LeafsData
    else
        warn(errorMsg)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errorMsg = pcall(function()
        datastore:SetAsync(player.UserId..' -Leafs', player.leaderstats.Leafs.Value)
    end)
    if success then
        print('Saved Data!')
    else
        warn(errorMsg)
    end
end)
game.Players.PlayerAdded:Connect(function(player)
    local RebirthData
    local success, errorMsg = pcall(function()
        RebirthData = datastore:GetAsync(player.UserId..' -Rebirths')
    end)
    if success then
        player.leaderstats.Rebirths.Value = RebirthData
    else
        warn(errorMsg)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errorMsg = pcall(function()
        datastore:SetAsync(player.UserId..' -Rebirths', player.leaderstats.Rebirths.Value)
    end)
    if success then
        print('Saved Data!')
    else
        warn(errorMsg)
    end
end)

game.Players.PlayerAdded:Connect(function(player)
    local ownsToolData
    local success, errorMsg = pcall(function()
        ownsToolData = datastore:GetAsync(player.UserId..' -ownsLog')
    end)
    if success then
        player.ownsLog.Value = ownsToolData
    else
        warn(errorMsg)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errorMsg = pcall(function()
        datastore:SetAsync(player.UserId.." -ownsLog", player.ownsLog.Value)
    end)
    if success then
        print('Saved Data!')
    else
        warn(errorMsg)
    end
end)

game.Players.PlayerAdded:Connect(function(player)
    if player.ownsLog.Value == true then
        game.ServerStorage.Inventory.Log:Clone(player:WaitForChild("Backpack"))
        print('Gave Tool')
    else
        print("Didn't Recieve Tool")
    end
end)



game:BindToClose(function()
    wait(3)
end)

1 answer

Log in to vote
0
Answered by 3 years ago

Just fixed it, literally just moved it up to the first function statement

Learn off of my mistake I guess:

local datastoreservice = game:GetService('DataStoreService')
local datastore = datastoreservice:GetDataStore('test')


game.Players.PlayerAdded:Connect(function(player)
    local TreesData
    local success, errorMsg = pcall(function()
        TreesData = datastore:GetAsync(player.UserId..' -Trees') 
    end)
    if success then
        player.leaderstats.Trees.Value = TreesData
    else
        warn(errorMsg)
    end

    player.CharacterAdded:Connect(function(char) -- Starts
    if player.ownsLog.Value == true then
        game.ServerStorage.Inventory.Log:Clone(player.)  -- Fixing Cloning
        print('Gave Tool')
    else
        print("Didnt Recieve Tool or Doesnt have tool")
        end
    end)
end)
Ad

Answer this question