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 4 years ago
01local UIS = game:GetService("UserInputService")
02local WeaponEquipped = false
03UIS.InputBegan:Connect(function(input)
04    if input.KeyCode == Enum.KeyCode.Q and script.Parent.Text ~= "Weapon slot empty." and WeaponEquipped == false then
05        WeaponEquipped = true
06        game.ReplicatedStorage[game.ReplicatedStorage.Slot.Value].Parent = game.Players.LocalPlayer.Character
07        script.Parent.Text = 'Press "Q" to unequip your '.. game.ReplicatedStorage.Slot.Value.. "."
08 end       
09end)
10UIS.InputBegan:Connect(function(input)
11    if input.KeyCode == Enum.KeyCode.Q and script.Parent.Text ~= "Weapon slot empty." and  WeaponEquipped == true then
12        WeaponEquipped = false
13        game.Players.LocalPlayer.Character[game.ReplicatedStorage.Slot.Value].Parent = game.ReplicatedStorage
14        script.Parent.Text = 'Press "Q" to equip your '.. game.ReplicatedStorage.Slot.Value.. "."
15 end
16end)

1 answer

Log in to vote
1
Answered by 4 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.

01local UIS = game:GetService("UserInputService")
02local WeaponEquipped = false
03 
04UIS.InputBegan:Connect(function(input)
05    if input.KeyCode == Enum.KeyCode.Q and script.Parent.Text ~= "Weapon slot empty." then
06    if WeaponEquipped ==  false then
07        WeaponEquipped = true
08        game.ReplicatedStorage[game.ReplicatedStorage.Slot.Value].Parent = game.Players.LocalPlayer.Character
09        script.Parent.Text = 'Press "Q" to unequip your '..game.ReplicatedStorage.Slot.Value.."."
10    else
11    WeaponEquipped = false
12        game.Players.LocalPlayer.Character[game.ReplicatedStorage.Slot.Value].Parent = game.ReplicatedStorage
13        script.Parent.Text = 'Press "Q" to equip your '..game.ReplicatedStorage.Slot.Value.."."
14    end
15    end       
16end)
Ad

Answer this question