Remote Event Firing twice crashes studio

I’m trying to make a two handed spiderweb shooting thing. Shooting one web works fine on both hands, but shooting from both hands at the same time does not, and it crashes studio.

If you wanna try it out, here is the place:
SpidermanBug.rbxl (51.8 KB)

I know that I didn’t include much information, but I don’t understand the problem, so I don’t know what to say. If you need more, just ask. :slight_smile:

Image of the hierarchy and where this script is: image_2022-11-19_122542044|254x480

Script (Module script that includes both Client and Server):

-- Services

local RS = game:GetService('RunService')
local TS = game:GetService('TweenService')
local UIS = game:GetService('UserInputService')
local SG = game.StarterGui
local plrs = game.Players

-- Objects

local slinger = script.Parent
local char = slinger.Parent
local hands = {
	Left = char:WaitForChild('LeftHand'),
	Right = char:WaitForChild('RightHand')
}
local bases = {
	Left = slinger:WaitForChild('Left'):WaitForChild('Base'),
	Right = slinger:WaitForChild('Right'):WaitForChild('Base')
}
local hooks = {
	Left = slinger.Left.Hook,
	Right = slinger.Right.Hook
}

-----------------

for i, v in pairs(bases.Left:GetChildren()) do
	v.Parent = char.LeftHand
end

bases.Left = char.LeftHand
hooks.Left.HookWeld.Part1 = char.LeftHand

for i, v in pairs(bases.Right:GetChildren()) do
	v.Parent = char.RightHand
end

bases.Right = char.RightHand
hooks.Right.HookWeld.Part1 = char.RightHand

-----------------

local springs = {
	Left = bases.Left:WaitForChild('Spring'),
	Right = bases.Right:WaitForChild('Spring')
}

-- Technicals

local messageEv = script:WaitForChild('Message')
local wasActive = false
--local debounce = false
--local debounceT = 0.5

-- Customization

local attachSounds = {
	Left = hands.Left:WaitForChild('Attach'),
	Right = hands.Right:WaitForChild('Attach')
}
local breakSounds = {
	Left = hands.Left:WaitForChild('Break'),
	Right = hands.Right:WaitForChild('Break')
}
local keys = {
	Left = Enum.KeyCode.Q,
	Right = Enum.KeyCode.E
}

local plr = nil
local m = nil -- Mouse

-- Current

local currentSKJ = { -- current Safe Keeping Joint
	Left = nil,
	Right = nil
}
local currentAJ = { -- current Arm Joint
	Left = nil,
	Right = nil
}
local currentT = { -- current Tween
	Left = nil,
	Right = nil
}

local GG = {} -- Module

function clientInit()
	local actives = {
		Left = false,
		Right = false
	}

	plr = plrs:GetPlayerFromCharacter(char)
	m = plr:GetMouse()
	m.TargetFilter = char

	char.Humanoid.Died:Connect(function()
		script:Destroy()
	end)

	RS.RenderStepped:Connect(function()
		m.Icon = 'rbxassetid://6879292858'

		for i, v in pairs(plr.Character:GetChildren()) do
			if string.match(v.Name, 'Arm') or string.match(v.Name, 'Hand') or string.match(v.Name, 'Leg') or string.match(v.Name, 'Foot') then
				v.LocalTransparencyModifier = 0
			end
		end
	end)

	-- Problem Start

	UIS.InputBegan:Connect(function(input)
		if input.KeyCode == keys.Left then -- Left
			local initialPos = hands.Left.Position
			local dist = (m.Hit.p - initialPos).Magnitude
			local hum = char.Humanoid
			--local shot = false

			--print(debounce)
			if not actives.Left and m.Target and dist < 300 --[[and not debounce]] then
				--debounce = true

				messageEv:FireServer(true, m.Hit.p, dist, m.Target, 'Left')
				hooks.Left.Cursor3D.Enabled = true

				--print('1')

				--task.wait(debounceT)

				--print('2')

				--debounce = false
				--shot = true

				actives.Left = true
			end	
		elseif input.KeyCode == keys.Right then -- Right
			local initialPos = hands.Right.Position
			local dist = (m.Hit.p - initialPos).Magnitude
			local hum = char.Humanoid
			--local shot = false

			--print(debounce)
			if not actives.Right and m.Target and dist < 300 --[[and not debounce]] then
				--debounce = true

				messageEv:FireServer(true, m.Hit.p, dist, m.Target, 'Right')
				hooks.Right.Cursor3D.Enabled = true

				--print('1')

				--task.wait(debounceT)

				--print('2')

				--debounce = false
				--shot = true

				actives.Right = true
			end
		end

		--print(shot)
	end)

	-- Problem End

	UIS.InputEnded:Connect(function(input)
		if input.KeyCode == keys.Left then
			local hum = char.Humanoid

			--if debounce then
			messageEv:FireServer(false, nil, nil, nil, 'Left')
			hooks.Left.Cursor3D.Enabled = false
			--end

			actives.Left = false
		elseif input.KeyCode == keys.Right then
			local hum = char.Humanoid

			--if debounce then
			messageEv:FireServer(false, nil, nil, nil, 'Right')
			hooks.Right.Cursor3D.Enabled = false
			--end

			actives.Right = false
		end
	end)
end

function serverInit()
	messageEv.OnServerEvent:Connect(function(player, active, targetPos, dist, trg, hand)	
		if active then
			GG.Fire(targetPos, dist, trg, hand)
		elseif wasActive then
			GG.Reset(player, hand)
		end
	end)
end

function init()
	if RS:IsClient() then
		clientInit()
	elseif RS:IsServer() then
		serverInit()
	end
end

function GG.Fire(targetPos, dist, trg, hand) -- hand is either 'Left' or 'Right'
	local initialPos = char[hand.. 'Hand'].Position
	local TI = TweenInfo.new(dist / 35, Enum.EasingStyle.Quint)
	local hook = hooks[hand]
	local base = bases[hand]
	local tween = TS:Create(base.Spring, TI, {FreeLength = dist / 25, Stiffness = math.clamp(dist * 2, 500, 2000)})
	currentSKJ[hand] = slinger[hand].JointSafeKeeping['Ragdoll'.. hand ..'Shoulder']
	currentAJ[hand] = char[hand.. 'UpperArm'][hand.. 'Shoulder']
	currentT[hand] = tween

	wasActive = true

	hook.HookWeld.Enabled = false

	wait()

	hook.Position = targetPos
	hook.WeldToTarget.Part0 = trg
	hook.HookWeld.Enabled = false
	springs[hand].FreeLength = dist
	base.Web.Enabled = true
	base.Web.TextureSpeed = dist / 50
	base.Web.TextureLength = dist / 50

	currentAJ[hand].Parent = slinger[hand].JointSafeKeeping
	currentSKJ[hand].Parent = char[hand.. 'UpperArm']
	currentSKJ[hand].Attachment0 = char[hand.. 'UpperArm'][hand.. 'ShoulderRigAttachment']
	currentSKJ[hand].Attachment1 = char.UpperTorso[hand.. 'ShoulderRigAttachment']
	currentAJ[hand].Part0 = nil
	currentAJ[hand].Part1 = nil

	tween:Play()
	attachSounds[hand]:Play()
end

function GG.Reset(player, hand)
	local hook = hooks[hand]
	local base = bases[hand]

	currentSKJ[hand] = slinger[hand].JointSafeKeeping[hand ..'Shoulder']
	currentAJ[hand] = char[hand.. 'UpperArm']['Ragdoll'.. hand.. 'Shoulder']

	wasActive = false

	if currentT[hand] then
		currentT[hand]:Cancel()
		breakSounds[hand]:Play()
	end

	hook.WeldToTarget.Part0 = nil
	hook.CFrame = char[hand.. 'Hand'].CFrame
	hook.HookWeld.Enabled = true
	hook.Anchored = false
	springs[hand].FreeLength = 1
	base.Web.Enabled = false

	currentAJ[hand].Parent = slinger[hand].JointSafeKeeping
	currentSKJ[hand].Parent = char[hand.. 'UpperArm']
	currentSKJ[hand].Part0 = char.UpperTorso
	currentSKJ[hand].Part1 = char[hand.. 'UpperArm']
	currentAJ[hand].Attachment0 = nil
	currentAJ[hand].Attachment1 = nil
	
	print(slinger[hand].JointSafeKeeping:GetChildren())
end

init()

return GG

This is pretty hard for me to understand and may be for you, but please try! Thank you! All help appreciated! :slight_smile:

You have placed a LocalScript and a server script inside the module Script

But, they don’t do anything. So why are they there?

You also have a lot of function inside your module script but they are outside the actual module function.

Why?

I don’t think module scripts really work the way you are trying to use it.

You should have a server script that calls functions from the module. Not a module script that runs functions and also prodives function to other scripts at the same time. That can cause the program to crash.

The local script runs the module script on just the players part of course, and the server script runs the server part of the module.

Yeah, I know that modules aren’t intended to be used this way, but it’s just for the convenience of having the client and server in one script. I also followed this tutorial:

so that’s why I used it this way.