Cloned tools from ServerStorage to a player's backpack sometimes do not work at all

I have this weapon selection GUI that is supposed to clone the selected tools (primary, secondary, and equipment) from the ServerStorage to a player’s backpack. Most times it works, but there are times where the tools do not work at all, and this is the case for all 3 tools.

I have tried disabling the local scripts in the tools and enabling them after they are cloned into the player’s backpack such as:

game.ReplicatedStorage.Items.Primary.GetMA5B.OnServerEvent:Connect(function(player,PlayerUsername)

if PlayerUsername == GetContentUsername then

local MA5BClone = game.ServerStorage.Weapons.MA5B:Clone()

MA5BClone.Parent = player.Backpack

MA5BClone.GunScript_Local.Disabled = false

end

end)

but the results are the same, the tools sometimes work and other times, they do not.

I have checked the Developer Console in-game and there seems to be no error with the scripts themselves.

1 Like

Try creating a reference to the tool that you want to clone. Then create a separate variable for the newly cloned tool using the original like this.

local ma5bOriginal = game.ServerStorage.Weapons.MA5B
game.ReplicatedStorage.Items.Primary.GetMA5B.OnServerEvent:Connect(function(player,PlayerUsername)

    if PlayerUsername == GetContentUsername then

        local MA5BClone = ma5bOriginal:Clone()
        MA5BClone.Parent = script.Parent.Parent.Parent.Backpack

        MA5BClone.GunScript_Local.Disabled = false
    end
end)
1 Like

Why do you do this? Why don’t you use the “player” argument that was passed through the :FireServer?

MA5BClone.Parent = player.Backpack

1 Like

Oops, my bad. I guess I’ll change that.

I had an issue with replicating as well, however the issue was the player was already spawned in when the tool was cloned into the player, but it would be an infinite loop waiting for something that already existed. Check for these:

local character = player.CharacterAdded:Wait() or player.Character

and switch them over to this:

local character = player.Character or player.CharacterAdded:Wait()

that way it just makes sure that the character isnt already there first.

Dont know if that was relevant, just a tip.

1 Like

I’ll try this today and will let you know about the results.

Your solution worked! Thank you.

1 Like