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

equip system doesn't work but i start game Value Don't create what is it? Help

Asked by 3 years ago

hi recently started to create my own game and there was a difficulty in the store I am asking for help 2 times already because I do not have special information in the field of scripting here is an error

ServerScriptService.LastEquipped:11: invalid argument #3 (string expected, got table)

here is the script itself

local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("Buy10")



game.ReplicatedStorage.GameClient.Events.RemoteEvent.PlayerLoaded.OnServerEvent:Connect(function(player)
    local equippedlast = Instance.new("StringValue")
    equippedlast.Name = "Equipped"
    local save = ds:GetAsync(player.UserId)
    if save then
        equippedlast.Value = save
    else
        local name
        for i, tool in pairs(game.ServerStorage.Tools:GetChildren()) do
            if tool:FindFirstChild("ItemNumber") then
                if tool.ItemNumber.Value == 1 then
                    name = tool.Name

                end
            end
        end
        equippedlast.Value = name
    end

    equippedlast.Parent = player

    local clone = game.ServerStorage.Tools:FindFirstChild(equippedlast.Value):Clone()
    clone.Parent = player:WaitForChild("Backpack")

end)



game.Players.PlayerRemoving:Connect(function(player)

    ds:SetAsync(player.UserId, player.Equipped.Value)

end)

1 answer

Log in to vote
1
Answered by
Ludzik78 136
3 years ago

save is a table, thats why it says string expected, got table. Print out the table, then do save['(write the name of the variable name your looking for here)'] instead of just save. Let me know if this doesnt work.

0
hello, could you explain where to write where StringValue is? YTBrainBroYT 29 — 3y
0
so your saying where StringValue is? as i was saying, replace the save at Line 11 with save['variablename] Ludzik78 136 — 3y
0
worked but got an error at line 27 ServerScriptService.LastEquipped:27: attempt to index nil with 'Clone' YTBrainBroYT 29 — 3y
Ad

Answer this question