01 | local UIS = game:GetService( "UserInputService" ) |
02 | local WeaponEquipped = false |
03 | UIS.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 |
09 | end ) |
10 | UIS.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 |
16 | end ) |
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.
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local WeaponEquipped = false |
03 |
04 | UIS.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 |
16 | end ) |