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

Can anyone help with this inventory script if statement??

Asked by 4 years ago
Edited 4 years ago

My inventory code is in serverscriptservice, but the if statement is underlined red, but I don't know what is wrong, I tried, doing then and else after the if statement. I put some * around the if

print("Hello world!")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("BackpackSave")

game.Players.PlayerAdded:Connect(function(player)
    pcall(function()
        local tool = dataStore:GetAsyne("User-"..player.UserId)
        if tool then
            for i,v in pairs(tool) do
                local toolFound = game.ReplicatedStorage.Items:FindFirstChild
                ***if*** toolFound then
                    toolFound:Clone().Parent = player.Backpack
                    toolFound:Clone().Parent = player.StarterGear
                end
            end
        end
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    pcall(function()
        local toolsSave = {}
        for i, tool in pairs(player.Backpack:GetChildren()) do
            if tool then 
                table.insert(toolsSave,tool.Name)
            end
        end
        dataStore:SetAsync("User-"..player.UserId,toolsSave)
    end)
end)
0
I'm pretty sure you need to do something like if toolFound = true then UNBANhappyniceguy5 52 — 4y
0
It still does not work RamenRobloxian 2 — 4y
0
there's a typo in the variable itself. "local toolFound = game.ReplicatedStorage.Items:FindFirstChild()" is what it should be above the if statement Quackshire 17 — 4y
0
still does not work RamenRobloxian 2 — 4y
0
even with both scripts together RamenRobloxian 2 — 4y

Answer this question