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