Remote events piling up

I’m sure this has a very simple solution, but I cannot think of one,
In my two scripts, I have to fire the client from the server (not sure of the correct terminology), however this is inside of a ‘ProximityPrompt.Triggered’ function.

Here is an example of what is happening

Server Script

local p = script.Parent
local model = p.Parent.Parent
local waterCF = model.Bucket.water.CFrame
local times = 0

script.Parent.TriggerEnded:Connect(function(plr)
	
	p.Enabled = false
	local char = workspace:FindFirstChild(plr.Name)
	model.UsedBy.Value = char.Name
	char.Archivable = true
	local hrp = char.HumanoidRootPart
	
	hrp.Anchored = true
	hrp.CFrame = model.stpos.CFrame * CFrame.new(0,3,0)
	
	local pat = char.RightHand.RightGripAttachment
	local sock = model.handle.BallSocketConstraint
	
	sock.Attachment1 = pat
	
	
	
	times = times + 1
	
	
game.ReplicatedStorage.events.pump:FireClient(plr,model)
	
	end)





game.ReplicatedStorage.events.pump.OnServerEvent:Connect(function(plr,val)
	if val then
		model.aud.sqek:Stop()
		model.aud.sqek:Play()
	else
		model.aud.sqek:Stop()
		model.aud.sqek:Play()
		model.aud.watr:Play()
		model.particle.PE.Enabled = true
		wait(0.85)
		model.particle.PE.Enabled = false
		
		
		local bucket = model.Bucket
		
		if bucket.water.Size.X < 1.34 then
		bucket.water.Size = Vector3.new(bucket.water.Size.X + 0.3375/times,1.4,1.4) 
			bucket.water.CFrame = bucket.water.CFrame * CFrame.new(0.3375/times/2,0,0)
		else
			
		end
		
		
	
	end
end)

game.ReplicatedStorage.events.pumpexit.OnServerEvent:Connect(function(plr,exit)
	if exit == 'exited' then
		if model.UsedBy.Value == plr.Name then
			model.handle.BallSocketConstraint.Attachment1 = nil
			model.UsedBy.Value = ''
			model.prompt.ProximityPrompt.Enabled = true
		end
		model.Bucket.water.Size = Vector3.new(0.05, 1.4, 1.4)
		model.Bucket.water.CFrame = waterCF
		
		local char = workspace:FindFirstChild(plr.Name)
		char.HumanoidRootPart.Anchored = false
		
	end
end)


Local Script

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
game.ReplicatedStorage.events.pump.OnClientEvent:Connect(function(pump)
	
	
	
	local char = plr.Character
local pumpUI = plr.PlayerGui.pumpGUI
	pumpUI.Enabled = true
	local cam = pump.cam
	local plrcam = workspace.Camera
	plrcam.CameraType = Enum.CameraType.Scriptable
	plrcam.CFrame = cam.CFrame
	plrcam.HeadLocked = false
	plrcam.CameraSubject = cam
	
	local animtor = char.Humanoid.Animator
	local up = pump.handle.up
	local down = pump.handle.down
	
	local updeb = false
	local downdeb = true
	
	local animup = nil
	animup = animtor:LoadAnimation(up)
	local animdown = nil
	animdown = animtor:LoadAnimation(down)
	
	if pump.UsedBy.Value == plr.Name then
		
	
	UIS.InputBegan:Connect(function(inp)
		if inp.KeyCode == Enum.KeyCode.Up or inp.KeyCode == Enum.KeyCode.DPadUp then
			if updeb == false then
				updeb = true
				
				if animdown ~= nil then
					
					animdown:Stop()
				end
				
		
			
				animup:Play()
				print ('test')
				game.ReplicatedStorage.events.pump:FireServer(true)
				
				
			wait(0.3)
				animup:AdjustSpeed(0)
				downdeb = false
				
				end
		end
	end)
	
	
	
	UIS.InputBegan:Connect(function(inp)
		if inp.KeyCode == Enum.KeyCode.Down or inp.KeyCode == Enum.KeyCode.DPadDown then
			if downdeb == false then
				downdeb = true
				
				
				if animup ~= nil then
					
					animup:Stop()
				end
				
				
				
				
					animdown:Play()
					print ('test')
				game.ReplicatedStorage.events.pump:FireServer(false)
				wait(0.3)
				animdown:AdjustSpeed(0)
				updeb = false
			end
			
		end
	end)
	
	
	
	
	UIS.InputBegan:Connect(function(inp)
		if inp.KeyCode == Enum.KeyCode.F or inp.KeyCode == Enum.KeyCode.ButtonX then
			animup:Stop()
			animdown:Stop()
			plrcam.CameraType = Enum.CameraType.Custom
			plrcam.CameraSubject = char.Humanoid
			plrcam.CFrame = char.HumanoidRootPart.CFrame
			plrcam.HeadLocked = true
			
				game.ReplicatedStorage.events.pumpexit:FireServer('exited')
				
				
		end
	end)
	
	end
	
end)


image_2021-08-11_063137

The first time the Proximity Prompt event would be activated it would be fine, but after that it would print test x2, test x3, test x4 and so on.

I have have tried implementing a debounce, moving the ‘FireClient:()’ outside of the Proximity Prompt event on the server script, however neither of those has worked.

I have noticed though, the issue only occurs while the ‘print’ is inside of the ‘InputBegan’ event, but I am not entirely sure why that is - unless I’ve missed something (most likely).

I assume the issue is within the local script though,

Sorry for the script formatting and messiness, hopefully It’s not illegible.

Event connections aren’t removed, you need to manually disconnect them. Alternatively, when the client event happens switch a bool that allows user input to go through instead of connecting inside the client event itself.

1 Like

Thank you, I didn’t even know that it was possible to disconnect events haha.