Getting the mouse from the server

So I want to pass the mouse to the server using a local script, it has a red line in the server script under the mouse.Target
https://gyazo.com/b293b12fb9b6979a9d29cdb6780e4593

localscript:

local Player = game:GetService("Players").LocalPlayer
script.Parent.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if mouse.Target.Parent:FindFirstChild("Humanoid") then
			local RepStorage = game:GetService("ReplicatedStorage")
			local ArrestEvent = RepStorage:FindFirstChild("Arrest")
			local mouse = Player:GetMouse()
			ArrestEvent:FireServer(mouse.Target)
		end
	end)
end)

server script:

local RepStorage = game:GetService("ReplicatedStorage")
local ArrestEvent = RepStorage:FindFirstChild("Arrest")

ArrestEvent.OnServerEvent:Connect(function(player, mouse.Target)
	print(mouse.Target)
end)

Remember that parameters are local variables, so you need to use a valid identifier. mouse.Target is not a valid identifier because it contains a period, but target for example is a valid identifier.

mmh, but I read this thread saying you could. Getting the players mouse from the server And I don’t quite understand what you’re saying.

Do you mean I should make target a variable?

What @sjr04 is trying to say is that you’re assigning the name “mouse.Target” to a parameter, which is an invalid name. You cannot have periods in variable names, among other things.

The simple fix is to change mouse.Target to mouse when you declare your parameters:

ArrestEvent.OnServerEvent:Connect(function(player, mouse) -- changed mouse.Target to mouse
	print(mouse.Target)
end)

Yeah, that didn’t work for me. https://gyazo.com/562da954a3d7708f75bce1c8ea303103

Which the server will receive as nil since the mouse instance is created locally. Pass the target directly not the mouse

cc @lavaaylla

oh, ok. Yeah I get that now, I feel dumb.

On localscript you should use mouse.Hit.p instead of mouse.Target

local Player = game:GetService("Players").LocalPlayer
script.Parent.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if mouse.Target.Parent:FindFirstChild("Humanoid") then
			local RepStorage = game:GetService("ReplicatedStorage")
			local ArrestEvent = RepStorage:FindFirstChild("Arrest")
			local mouse = Player:GetMouse()
			ArrestEvent:FireServer(mouse.Hit.p)
		end
	end)
end)

On Server it should receive the signal of mouse.Hit.p

local RepStorage = game:GetService("ReplicatedStorage")
local ArrestEvent = RepStorage:FindFirstChild("Arrest")

ArrestEvent.OnServerEvent:Connect(function(player, mousePosition)
	print(mousePosition)
end)

Bruh the threads a year old…

1 Like

localscript:

local Player = game:GetService("Players").LocalPlayer
script.Parent.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if mouse.Target.Parent:FindFirstChild("Humanoid") then
			local RepStorage = game:GetService("ReplicatedStorage")
			local ArrestEvent = RepStorage:FindFirstChild("Arrest")
			local mouse = Player:GetMouse()
			ArrestEvent:FireServer(mouse.Target)
		end
	end)
end)

server script:

local RepStorage = game:GetService("ReplicatedStorage")
local ArrestEvent = RepStorage:FindFirstChild("Arrest")

ArrestEvent.OnServerEvent:Connect(function(player, mouseTarget)
	print(mouseTarget)
end)

Try this

1 Like

Bro I don’t need it, it’s been a year

But did the game work out tho :eyes:

1 Like