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.
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)
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.