End goes on and on

everytime i script there is a high chance i go on a long scripting breakdown of ends just erroring and erroring.

this is one of those breakdowns.

this is a local script in starterplayerscripts, anybody have an idea on how the ends should be to make it not error?

--- MK43
local Deagle = require(script.GunModules.Deagle)
local userInputService = game:GetService("UserInputService")
local gunspawners = workspace.GunSpawners:GetChildren()

for i,v in pairs(game.Workspace.GunSpawners:GetChildren()) do
	v.Touched:connect(function(hit)
		Deagle.EquipGun()
		game.Workspace["HasGun?"].Value = 1
		game.Workspace.AmmoValue.Value = 11
		game.ReplicatedFirst.musicfolder.sfx.gunshoot1.PlaybackSpeed = 1
		for i,v in pairs(game.Workspace.GunSpawners:GetChildren()).CanTouch == false do
		userInputService.InputBegan:Connect(function(input)
			if input.KeyCode == Enum.KeyCode.Q then
				game.Workspace.map1["destroy-whenshoot"].CanCollide = false
				game.Workspace.map1["destroy-whenshoot"].Transparency = 1
				local desert = game.Workspace.Camera:FindFirstChild("Desert_Eagle")
				game.Workspace.AmmoValue.Value -= 1
				desert.viewmodel.Decal.Transparency = 1
				desert.viewmodelSHOOT1.Decal.Transparency = 0
				game.ReplicatedFirst.musicfolder.sfx.gunshoot1:Play()
				task.wait(0.2)
				desert.viewmodelSHOOT1.Decal.Transparency = 1
				desert.viewmodelSHOOT2.Decal.Transparency = 0
				task.wait(0.1)
				desert.viewmodelSHOOT2.Decal.Transparency = 1
				desert.viewmodel.Decal.Transparency = 0
				Deagle.BulletTrue()
				task.wait(0.5)
				Deagle.BulletFalse()
				end
			end)
	    end

if game.Workspace.weaponREMOVER.Touched:Connect(function()
		Deagle.UnequipGun()
		game.Workspace["HasGun?"].Value = 0
		game.ReplicatedFirst.musicfolder.sfx.gunshoot1.PlaybackSpeed = 0
userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		print("no gun")
					end
				end)
			end) then
		end
	end

hi mate does it help if you end the if statment :
if game.Workspace.weaponREMOVER.Touched:Connect(function()

:+1:

Your script seems very messy, but the end should automatically get created when you create a function or make an if statement when you go on the next line (by pressing the Enter button).

Try using this code for your script:

--- MK43
local Deagle = require(script.GunModules.Deagle)
local userInputService = game:GetService("UserInputService")
local gunspawners = workspace.GunSpawners:GetChildren()

for i,v in pairs(game.Workspace.GunSpawners:GetChildren()) do
	v.Touched:connect(function(hit)
		Deagle.EquipGun()
		game.Workspace["HasGun?"].Value = 1
		game.Workspace.AmmoValue.Value = 11
		game.ReplicatedFirst.musicfolder.sfx.gunshoot1.PlaybackSpeed = 1
		for i,v in pairs(game.Workspace.GunSpawners:GetChildren()).CanTouch == false do
			userInputService.InputBegan:Connect(function(input)
				if input.KeyCode == Enum.KeyCode.Q then
					game.Workspace.map1["destroy-whenshoot"].CanCollide = false
					game.Workspace.map1["destroy-whenshoot"].Transparency = 1
					local desert = game.Workspace.Camera:FindFirstChild("Desert_Eagle")
					game.Workspace.AmmoValue.Value -= 1
					desert.viewmodel.Decal.Transparency = 1
					desert.viewmodelSHOOT1.Decal.Transparency = 0
					game.ReplicatedFirst.musicfolder.sfx.gunshoot1:Play()
					task.wait(0.2)
					desert.viewmodelSHOOT1.Decal.Transparency = 1
					desert.viewmodelSHOOT2.Decal.Transparency = 0
					task.wait(0.1)
					desert.viewmodelSHOOT2.Decal.Transparency = 1
					desert.viewmodel.Decal.Transparency = 0
					Deagle.BulletTrue()
					task.wait(0.5)
					Deagle.BulletFalse()
				end
			end)
		end
	end)
end

game.Workspace.weaponREMOVER.Touched:Connect(function()
	Deagle.UnequipGun()
	game.Workspace["HasGun?"].Value = 0
	game.ReplicatedFirst.musicfolder.sfx.gunshoot1.PlaybackSpeed = 0
	userInputService.InputBegan:Connect(function(input)
		if input.KeyCode == Enum.KeyCode.Q then
			print("no gun")
		end
	end)
end)
1 Like