I made this script to equip a tool on touch as i have backpack disabled and only want the tool to be equipped when entering a specific area.
function onTouched(hit) if game.ServerStorage.Main.Values.ToolEquip.Value == 0 then hit.Parent.Humanoid:EquipTool(game.ServerStorage.Main.Parts.R15) game.ServerStorage.Main.A1Enemies:Clone().Parent = game.Workspace.Npc game.ServerStorage.Main.Values.ToolEquip.Value = 1 end end connection = script.Parent.Touched:connect(onTouched)
The Value of "ToolEquip" is 0, and this gets no errors.
If you have backpack disabled, you can allow the player not to manually equip it. So you can still have the tools in starterpack, as you normally would.
To ensure you have backpack disabled the correct way, refer to this.
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) --In a LocalScript within StarterPlayerScripts
Then you can prevent the player from equipping the tool, by enabling ManualActivationOnly.(A property of the tool class.) Once you do that, you can use this code to equip the tool.
Player.Character.Humanoid:EquipTool(Player.Backpack:FindFirstChild("toolname"))
Thank you "RubenKan" and "GottaHaveAFunTime", I took both your advice and it works, I cloned instead of moving it and cloning it into the Player instead of equipping it from ServerStorage fixed it.
This script works if anyone needs it for their game also to show you what i changed to fix it.
function onTouched(hit) if game.ServerStorage.Main.Values.ToolEquip.Value == 0 then game.ServerStorage.Main.Parts.R15:Clone().Parent = hit.Parent game.ServerStorage.Main.A1Enemies:Clone().Parent = game.Workspace.Npc game.ServerStorage.Main.Values.ToolEquip.Value = 1 script.Parent.Parent.Tool2.ToolEquip.Disabled = true script.Disabled = true end end connection = script.Parent.Touched:connect(onTouched)
I appreciate all the help, the game if you're wondering is "/games/768440986/No-Name-Quest" Have a great day :).