I’m trying to make it so that my webs stay visible while im holding either Q or E and I’m in need of help with the holding down of keys through a remote event because I can’t quite get it, because once the InputEnded function runs it fires the remote again and it messes it up, any help would be appreciated alot thanks!
Local Script :
local QHeld = false
local EHeld = false
UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.E then
if not EHeld then
EHeld = true
local E = 2
Web:FireServer(mouse.Hit, E , mouse.Target, EHeld)
end
end
if input.KeyCode == Enum.KeyCode.Q then
if not QHeld then
QHeld = true
local Q = 1
Web:FireServer(mouse.Hit, Q , mouse.Target, QHeld)
end
end
end)
UIS.InputEnded:Connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.E then
if EHeld then
EHeld = false
local E = 2
Web:FireServer(mouse.Hit, E, mouse.Target, EHeld)
end
end
if input.KeyCode == Enum.KeyCode.Q then
if QHeld then
QHeld = false
local Q = 1
Web:FireServer(mouse.Hit, Q, mouse.Target, QHeld)
end
end
end)
Basically I check on the server the value of EHeld and QHeld and I print it, but the thing is when the InputEnded function passes through it messes up that while loop for when held is true for both bools and it goes infinitely until I press one of the keys again, hold on let me show you what I mean
That wasn’t even the whole issue and also it was kind of hard to explain
Server Script :
Web.OnServerEvent:Connect(function(plr, hit, letter, target, held)
local LeftHand = plr.Character:WaitForChild("Left Arm")
local RightHand = plr.Character:WaitForChild("Right Arm")
local webShooterR = RightHand:WaitForChild("webShooterR")
local webShooterL = LeftHand:WaitForChild("webShooterL")
local rAttach = RightHand:WaitForChild("AttachRight")
local lAttach = LeftHand:WaitForChild("AttachLeft")
local char = plr.Character
local humrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local Animations = game.ServerStorage.Animations
while held do
game:GetService("RunService").Stepped:Wait()
print(held)
end
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.A then --Replace A with what you want
--what you want to happen
end
end)
This will open a loop that will never end. Every time an event is fired, it connects it to a function. If there are multiple fires, then the event will connect each fire to a different function instance.
Unfortunately that’s what is causing your problem so you will definitely have to do that.
Here’s a quick mock up of a solution.
local PlayersHolding = {}
Web.OnServerEvent:Connect(function(plr, hit, letter, target, held)
local LeftHand = plr.Character:WaitForChild("Left Arm")
local RightHand = plr.Character:WaitForChild("Right Arm")
local webShooterR = RightHand:WaitForChild("webShooterR")
local webShooterL = LeftHand:WaitForChild("webShooterL")
local rAttach = RightHand:WaitForChild("AttachRight")
local lAttach = LeftHand:WaitForChild("AttachLeft")
local char = plr.Character
local humrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local Animations = game.ServerStorage.Animations
PlayersHolding[plr] = held --Ok not really ideal to use plr as the disctionary but you know how to fix that or whatever
--ALSO this is a HUGE security risk so fix that lol
end
while true do
for plr, holding in pairs(PlayersHolding) do
if holding then
--Do yo thang
end
end
end
Essentially - you can fire the same RemoteEvent but it will act as a totally new function and will keep it open forever in your original code.
Here we use your original Remote to set the value of a table which a further loop will constantly check.
The further loop will constantly loop through the table of players holding and it will do its thing for each player
I hope my explanations made sense and my pseudocode was a good resource. If you have any questions just continue to reply to me and I’ll answer them in this thread.
If not and this helped you solve the issue be sure to mark it as solved.
Yea spencer its currently not solved but Im gonna try making a remote event that handles just the bools and well see how that goes, see you in probably a few minutes
But on a serious note thank you for actually helping!