Help with gun randomizer

Hi there I wanted to make a gun script that randomized the guns going into the players backpack and it worked perfectly but now that I disable the backpack it doesn’t work of course. I read about all I have to do is instead of putting the “gun” into the backpack teleport it a stud above the players head and it would work fine.
I don’t know how to do that.
Code:


Anyways thanks!

Try using the This to equip the Tool.

It doesn’t Randomize the guns I have multiple guns and they are randomized so I dont think this will work but what do I know

I am assuing you have Disabled the Backpack CoreUI and you cannot equip the Tool?

I disable the backpack with this script in starter GUI

What is the actual issue you are encountering? Is the tool not equipping or is the tool not being given to the player?

the tool isnt being equiped because the backpack doesnt exist so instead of putting the gun in the backpack teleport it above the players head so they pick it up

This is not a practical solution, use Humanoid:EquipTool Instead to equip the Tool. When you disable the backpack CoreGui it only Disables the Gui not the actual Backpack.

Parent the tool to the character, instead of the backpack. They will automatically equip it.

This method causes Issues, the recommended method of doing it is using EquipTool.

Yes but I still need the guns to be randomized so there needs to be code for the script to make this tool go 2 studs above the player

What issues? Parenting the tool to the character is practically the same thing as Humanoid:EquipTool()

In fact the only issue I can thing of on the top of my head that you can’t use it on the client, which isn’t much of a problem in this case

Why do you need the Tool to go 2 studs above the Player? What are you trying to achieve by doing this?

I read that if it just teleports to the player instead of the player backpack then it would work

Try using this.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local Guns = game:GetService("ServerStorage").Guns:GetChildren()
		local randomGun = Guns[math.random(1, #Guns)]:Clone()
		randomGun.Parent = player.Backpack
		character:FindFirstChild("Humanoid"):EquipTool(randomGun)
	end)
end)

P.S please Instead of posting a picture of your code post the code and enclose it with ```

jesus im sorry thats painful queen thanks