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

I tried to make a sword equip/unequip with the q key and it stops working when you equip it?

local UIS = game:GetService("UserInputService")
local WeaponEquipped = false
UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q and script.Parent.Text ~= "Weapon slot empty." and WeaponEquipped == false then
		WeaponEquipped = true
		game.ReplicatedStorage[game.ReplicatedStorage.Slot.Value].Parent = game.Players.LocalPlayer.Character
		script.Parent.Text = 'Press "Q" to unequip your '.. game.ReplicatedStorage.Slot.Value.. "."
 end		
end)
UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q and script.Parent.Text ~= "Weapon slot empty." and  WeaponEquipped == true then
		WeaponEquipped = false
		game.Players.LocalPlayer.Character[game.ReplicatedStorage.Slot.Value].Parent = game.ReplicatedStorage
		script.Parent.Text = 'Press "Q" to equip your '.. game.ReplicatedStorage.Slot.Value.. "."
 end
end)

1 answer

✓ Accepted answer

First of all, we could do all of this in one event connection. Just some edits and we should be good to go.

I would explain all of this, but I'm just too lazy to do that, so here's the code. Let me know if you have any questions or issues.

Also you might wanna format this, just saying.

local UIS = game:GetService("UserInputService")
local WeaponEquipped = false

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.Q and script.Parent.Text ~= "Weapon slot empty." then
	if WeaponEquipped ==  false then
        WeaponEquipped = true
        game.ReplicatedStorage[game.ReplicatedStorage.Slot.Value].Parent = game.Players.LocalPlayer.Character
        script.Parent.Text = 'Press "Q" to unequip your '..game.ReplicatedStorage.Slot.Value.."."
	else
	WeaponEquipped = false
        game.Players.LocalPlayer.Character[game.ReplicatedStorage.Slot.Value].Parent = game.ReplicatedStorage
        script.Parent.Text = 'Press "Q" to equip your '..game.ReplicatedStorage.Slot.Value.."."
	end
	end        
end)

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