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

Equip and Unequip part by pressing a button help?

Hi so what i need help with is, that when i press a button a torch is clone to my hand, and so basically when you press F the torch "equips" when you press F again it "dequips" and when you press it after it "dequips" it equips and so on, but so far after dequipping it wont requip pleas help me.

repeat wait() until game.Players.LocalPlayer.Character
local character = game.Players.LocalPlayer.Character
local Handle = game.ReplicatedStorage['Torch']:Clone()
local Fire = game.ReplicatedStorage['FireForTheTorch']:Clone()
local UIS = game:GetService('UserInputService')
local cooldown = true
local otherdown = true
local animation = Instance.new('Animation')
local buttondown = true
wait()
UIS.InputBegan:Connect(function(input, processed)
    -- 'processed' will be 'true' if Roblox already handled that input.
    -- We shouldn't handle it in that case.
    if not processed then
        if input.KeyCode == Enum.KeyCode.F then
        cooldown = false
        local Rhand = character:findFirstChild('RightHand')
        Handle.Parent = game.Players.LocalPlayer.Character
        Fire.Parent = game.Players.LocalPlayer.Character
        local torso = character:findFirstChild('UpperTorso')
        Handle.CFrame = Rhand.CFrame
        Fire.CFrame = Rhand.CFrame
        local weld = Instance.new("Weld")
        weld.Part0 = Handle
        weld.C0 = Handle.CFrame:inverse()    
        weld.Part1 = Fire
        weld.C1 = Fire.CFrame:inverse()
        weld.Parent = Handle
        local weld2 = Instance.new("Weld")
        weld2.Part0 = Rhand
        weld2.C0 = Rhand.CFrame:inverse()    
        weld2.Part1 = Handle
        weld2.C1 = Handle.CFrame:inverse()
        weld2.Parent = Handle
        
if processed then
wait(3)
end
end
end
wait()
cooldown = true
end)

UIS.InputBegan:Connect(function(input, processed)
    -- 'processed' will be 'true' if Roblox already handled that input.
    -- We shouldn't handle it in that case.
    if not processed then
        if input.KeyCode == Enum.KeyCode.F then
            otherdown = false
        character:findFirstChild('Torch'):Destroy()
        character:findFirstChild('FireForTheTorch'):Destroy()
        
        end
    end
    wait()
otherdown = true
end)

1 answer

✓ Accepted answer

I have found a simpler way of doing this, First put 2 localscripts inside StarterGui, then call one of them Equip and the other Unequip, For Equip put in

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key)
		Key = Key:lower()
		if Key == 'f' then
	game.Workspace:FindFirstChild(Player.Name).Humanoid:EquipTool(Player.Backpack.BigSword)
	script.Parent.Unequip.Disabled = false
	script.Disabled = true
		end
end)

And For Unequip put in

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key)
		Key = Key:lower()
		if Key == 'f' then
	game.Workspace:FindFirstChild(Player.Name).BigSword:remove()
	game.ReplicatedStorage.BigSword:clone()
	game.ReplicatedStorage.BigSword:clone().Parent = game.Players.LocalPlayer.Backpack
	script.Parent.Equip.Disabled = false
	script.Disabled = true
		end
end)

Tho you will have to change a few things: Button ( if u want) Tool name (Where it says BigSword) And also put the tool you want in Replicated Storage

1 comment

0

That should work, Hope you like it C:

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