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

How to deal with this? I have been sitting for a long time but I could not understand - Help

Asked by 3 years ago

hello, I decided to continue making the game, but unfortunately I have a lot of knowledge in the IT sphere, I don’t have a mistake here

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

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(0)
    clone.Parent = player:WaitForChild("Backpack")

end)



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

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

end)
0
Try removing the "0" from the parentheses Omq_ItzJasmin 666 — 3y
0
I edited my answer. Just for a notification incase you did not know. Xapelize 2658 — 3y
0
I edited my answer again. Just for a notification incase you did not know. Xapelize 2658 — 3y

1 answer

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Usually “attempt to index nil value” errors happen when something has not loaded yet (If you have your hierarchy set up correctly).

You can consider doing:

 local clone = game.ServerStorage.Tools:FindFirstChild("equippedlast").Value:Clone()

EDIT:

If there was a property called "Value" in equippedlast, you can do:

 local clone = game.ServerStorage.Tools:FindFirstChild("equippedlast")["Value"]:Clone()

I think you meant for this?

Ok, after looking at your image, I want to say that "Value" is uncloneable and it's a property. Consider using:

 local clone = game.ServerStorage.Tools:FindFirstChild("equippedlast"):Clone()
0
This might probably work, i hope Xapelize 2658 — 3y
0
hello, I tried your method, but unfortunately it does not work, but I noticed one thing for some reason, in place of Value, there is already another value YTBrainBroYT 29 — 3y
0
yes, the old error is gone, but now a new one has appeared for the place) ServerScriptService.LastEquipped:27: attempt to index nil with 'Value' YTBrainBroYT 29 — 3y
0
Can you show me or explain the explorer about where is the "equippedlast" located at Xapelize 2658 — 3y
View all comments (3 more)
0
0
after the introduction of this value, the script began to issue the old error, that is ServerScriptService.LastEquipped:27: attempt to index nil with 'Clone' YTBrainBroYT 29 — 3y
0
Also, when deleting cloning, an error appeared ServerScriptService.LastEquipped:28: attempt to index nil with 'Parent' YTBrainBroYT 29 — 3y
Ad

Answer this question