Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 3 years ago
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

Log in to vote
1
Answered by 3 years ago

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)
Ad

Answer this question