Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would i make it so when a player joins, they auto equip a weapon?

I need it so that if a player spawns they auto equip a weapon. (I'm new to scripting, so can you put the entire script, and where to put it) Currently to hide back pack i'm using this script

local CoreGui = game:GetService("StarterGui")

CoreGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) 
CoreGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false) 

2 comments

0

There is no "easy" way to do this. Unfortunately, if you disable the backpack, then the tools won't work. I'm assuming you want the weapon to automatically give to the player without the tool being visible to the player's toolbar. In order to do something like this, you'd have to create a custom backpack.

0

To do that you don't need any script if you are making a wepon put it in starter pack if u got a wepon from the toolbox just press it and make sure its in starter pack. So when a player spawns with it they will auto equip the weapon.

2 answers

✓ Accepted answer

You're disabling the backpack, but luckily the tool still exists within the player's backpack and we can equip it using the EquipTool method. The tool still won't show as equipped since the toolbar is disabled, but it will be equipped. You can do this from either the server or the client, but I will be demonstrating the client-side implementation. For most convenience I recommend this localscript to be in StarterCharacterScripts, which will run every time the character is added.

local Players = game:GetService("Players")

local Character = script.Parent
local LocalPlayer = Players.LocalPlayer
local Backpack = LocalPlayer.Backpack
--At this point in time you can define a tool variable to be equipped.
local Tool = Backpack:FindFirstChild("testTool")

if Tool then
	Character:WaitForChild("Humanoid"):EquipTool(Tool)
	--Equip the tool
end

1 comment

0

thanks, really helped!

game.Players.PlayerAdded:Connect(function(Player)
	--Tool will be used here without reference. Just assign Tool or whatever variable you need.

	Player.CharacterAdded:Connect(function(Character)
		Character:WaitForChild("Humanoid"):EquipTool(Tool)
	end)
end)	

This code will equip whatever tool you assign to the Tool variable whenever the player's character is created.

This discussion is preserved as it was. New answers, comments, and votes are closed.