local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:Wait()
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local desiredKey = Enum.KeyCode.E
local function keyIsDown()
return UserInputService:IsKeyDown(desiredKey)
end
local tool = player.Backpack:WaitForChild("HoldTool")
local handle = tool.Handle
local isHeld = false;
local function equipTool()
if keyIsDown() then
if isHeld == false then
humanoid:EquipTool(tool)
else if isHeld == true then
return
end
end
else
humanoid:UnequipTools()
end
end
RunService.Heartbeat:Connect(equipTool)
I have no idea if this is the most optimal, but it works for me.
It uses a combination of RunService and UserInput.
Every heartbeat, it checks if the key is down, and if it is, equip it. I did a check if it was held in fear that it might look weird if you kept equipping the tool over and over again.
1 comment
Oops: I forgot! The script runs in StarterCharacterScripts