I am creating something again. This time, there is a reason and of course, it doesn't work xd. So basically, it should fire an event every time the player hold button 1 down. I have checked, it doesn't even fire the event. There is no error.

Local Script:

--// Main Variables \\--
local programFolder = script.Parent.Parent.Parent
local tool = programFolder.Parent
local firePart = tool:FindFirstChild("FirePart")
local userInputSerivce = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
--// Toggles \\--
local mouseDown = false
--// Remote Events \\--
local registerShot = programFolder.Remotes:WaitForChild("RegisterShot")
local registerAnimation = programFolder.Remotes:WaitForChild("RegisterAnimation")
--// Functions \\--
tool.Equipped:Connect(function()
	registerAnimation:FireServer("Equip")
	
	userInputSerivce.InputEnded:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			mouseDown = false
		end
	end)
	
	userInputSerivce.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			mouseDown = true
			
			repeat
				local information = {
					firePartPosition = firePart.CFrame.Position,
					mousePosition = mouse.Hit.Position,
					toolHandlePosition = tool.Handle.CFrame.Position,
				}
				
				registerShot:FireServer({information.firePartPosition, information.mousePosition, information.toolHandlePosition})
				wait(0.02)
			until not mouseDown
		end
	end)
end)

Server Script: - works fine.-

--// Main Variables \\--
local programFolder = script.Parent.Parent.Parent
local tool = programFolder.Parent
local animations = game:GetService("ReplicatedStorage").Animation
local remotes = programFolder:WaitForChild("Remotes")
local values = programFolder:WaitForChild("Values")
local config = programFolder.Scripts.Module.Settings
local damage = math.random(5, 10)
local equipAnimation = nil
--// Functions \\--
remotes:FindFirstChild("RegisterShot").OnServerEvent:Connect(function(fired, args)
	print("Fired???")
	local ray = Ray.new(args[3], (args[2] - args[1]).Unit * 300)
	local castedRay, position = workspace:FindPartOnRay(ray, fired.Character, false, true)
	
	local distance = (args[1] - position).Magnitude
	
	local bullet = Instance.new("Part")
	bullet.Size = Vector3.new(0.03, 0.03, distance)
	bullet.CFrame = CFrame.new(args[1], position) * CFrame.new(0, 0, - distance/2)
	bullet.Material = Enum.Material.SmoothPlastic
	bullet.BrickColor = BrickColor.new("Daisy orange")
	bullet.CanCollide = false
	bullet.Transparency = 0.5
	bullet.Parent = workspace.RayIgnore
	
	game:GetService("Debris"):AddItem(bullet, 0.1)
	
	if castedRay then
		local humanoid
		
		if castedRay.Parent:IsA("Accessory") or castedRay.Parent:IsA("Hat") then
			humanoid = castedRay.Parent.Parent:FindFirstChild("Humanoid")
		else
			if castedRay.Parent.Parent:FindFirstChild("Humanoid") then
				humanoid = castedRay.Parent.Parent:FindFirstChild("Humanoid")
			else
				pcall(function()
					humanoid = castedRay.Parent.Parent:FindFirstChild("Zobmie")
				end)
			end
		end
		
		if humanoid then
			humanoid:TakeDamage(damage)
		end
	end
end)

3 comments

0

Why is find first child in a pcall

0

also it is recommended to have toggle firing when making automatic guns

0

What do you mean by toggle firing?