Ad
Log in to vote
1

checked on a separate map, everything worked after I went to my map, bugs started right away???

Asked by 7 months ago

Hello, I am a beginner game developer I take a lot of scripts from the Internet and this is no exception I took the script to the store, I checked it everything works, but when I went into my game, I got this error

ServerScriptService.LastEquipped:27: attempt to index nil with 'Clone'

there are also pictures - https://imgur.com/a/dsQd8mu

and here is the script itself

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



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)
0
Incase the notification did not notificate you, I edited my answer Xapelize 2001 — 7mo

1 answer

Log in to vote
0
Answered by
Xapelize 2001 Moderation Voter Community Moderator
7 months ago
Edited 7 months ago

Try replacing line 27 to:

local clone = game:GetService("ServerStorage"):WaitForChild(Tools[equippedlast.Value]):Clone()
0
fixed but there was a new error - Green Katana is not a valid member of Folder "ServerStorage.Tools" YTBrainBroYT 29 — 7mo
0
new error - ServerScriptService.LastEquipped:27: attempt to index nil with 'Katana' YTBrainBroYT 29 — 7mo
Ad

Answer this question