GetMouse() not working?

I am working on a taser in Roblox studio and I use collection service to connect to the taser, my script has no error and red line but it didn’t work. Can someone fix this?

Server(Server Script):

local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local events = ReplicatedStorage:WaitForChild("Events")

local stunnedTime = 5

local function fire(target, position, item)
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = {target.Character}
	params.FilterType = Enum.RaycastFilterType.Blacklist

	local result = workspace:Raycast(item.Handle.Position, (position - item.Handle.Position) * 80, params)

	if result then
		local hit = result.Instance
		local model = hit:FindFirstAncestorOfClass("Model")

		if model and model.Name == "Caty" then
			print("Founded")
			if model:FindFirstChild("Humanoid") then
				local stunned = model.Humanoid:LoadAnimation(model.Humanoid.Stunned)

				if model:FindFirstChild("Kill") then
					model:FindFirstChild("Kill").Disabled = true
				end


				model.HumanoidRootPart.Anchored = true
				model.Humanoid.WalkSpeed = 0
				stunned:Play()
				wait(stunnedTime)
				model:FindFirstChild("Kill").Disabled = false
				model.HumanoidRootPart.Anchored = true
				model.Humanoid.WalkSpeed = 16
				stunned:Stop()
			end
		end
	end

end

for _, item in pairs(CollectionService:GetTagged("Item")) do
	if item.Name == "Taser" then
		events:WaitForChild("fireEvent").OnServerEvent:Connect(function(player, mousePos)
			fire(player, mousePos)
		end)
	end
end

Client(Local Script):

local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local events = ReplicatedStorage:WaitForChild("Events")

local function connect(click, event)
	event:FireServer(click.Hit.p)
end

for _, item in pairs(CollectionService:GetTagged("Item")) do
	if item.Name == "Taser" then
		local taser = item
		local mouse = game.Players.LocalPlayer:GetMouse()
		local fireEvent = events:WaitForChild("fireEvent")

		taser.Equipped:Connect(function()
			mouse.Button1Down:Connect(function()
				connect(mouse, fireEvent)
			end)
		end)
	end
end

EDIT: Those script located in ServerScriptServie

Only the server script is in ServerScriptServie right?

No,the both of them is located in the same place

Local scripts doesn’t work in ServerScriptService, try putting it in StarterPlayerScripts

https://developer.roblox.com/en-us/api-reference/class/LocalScript

1 Like

After I set the parent of the client script to StarterPlayerScript, this pop up on my output:
image

Seems like you aren’t passing the “item” argument when calling the function.

What should I do to fix it? I didn’t event understand where is the error some from

It’s okay, I just realize the mistake

The mistake:

events:WaitForChild("fireEvent").OnServerEvent:Connect(function(player, mousePos)
	fire(player, mousePos, "Missing")
end)