Hello wonderful People,
I have got a question to the Keypressing event. Like if you press E that you equip a vest and if you click it again you unequip it can somebody help me there out? Thank you very much,
Your Sincerely,
iSxny
Hello wonderful People,
I have got a question to the Keypressing event. Like if you press E that you equip a vest and if you click it again you unequip it can somebody help me there out? Thank you very much,
Your Sincerely,
iSxny
Hmmm, I am not sure I can help with the vest but I can help with the keypress.
game:GetService("UserInputService").InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
--Your Code Here
end
end)
Hope this helps
local VestEquipped = false
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input, GameProcessed)
if GameProcessed then return end
if Input.KeyCode == Enum.KeyCode.E then
if not VestEquipped then
-- Equip Vest
else
-- Unequip Vest
end
end
end)
-- Consider using RemoteEvents for this.
--get player
local player= game.Players.LocalPlayer
--get character of the player
local character= player.Character
--get Humanoid of the character
local humanoid= character.Humanoid
--callout user input service
local useriNPutService= game:GetService("UserInputService")
--variable for isequipped on the character right now
local isequipped=false
--key to press to equip your west
local keytopress=Enum.KeyCode.E
--above variable "keytopress" contains the value e of the keyboard input
--your accessory
--if it is in replicatedstorage
local replicatedStorage=game:GetService("ReplicatedStorage")
local accessory =replicatedStorage:FindFirstChild("")--"input accessory name"
useriNPutService.InputBegan:Connect(function(keypressedbyplayer)
--if the keypressedbyplayer is == keytopress
--or another meaning
--if keypressed==E
if keypressedbyplayer==keytopress then
if isequipped==false then
--if "isequipped"=false or
--you can write it as not "isequipped"
isequipped=true--1st set the "isequipped"=true
--clone your accessory and equip it to the character
humanoid:AddAccessory(accessory:Clone())
else
--when the key is pressed and
--if "isequipped"=true or
isequipped=false--1st set the "isequipped"=false
local equippedaccessory=character:FindFirstChild("")--input equipment name
equippedaccessory:Destroy()--destroy the same accessory from the character
end
end
end)