Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does it say mouse is a nil value?

Local Script:

local plrmouse = game.Players.LocalPlayer:GetMouse()

game.ReplicatedStorage.Events.SendMouse:FireServer(plrmouse)

plrmouse.Button1Down:Connect(function()
	game.ReplicatedStorage.Events.Clicked:FireServer(plrmouse)
end)

Regular Script:

local plr
local mouse


function whichsquare(plrmouse)
	print(plrmouse.Target.Name)
end


game.Workspace.Plot1.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not plr then
			plr = hit.Parent.Name
		end
	end
end)

game.ReplicatedStorage.Events.SendMouse.OnServerEvent:Connect(function(plr,plrmouse)
	print(plrmouse.ClassName)
	mouse = plrmouse
end)

game.ReplicatedStorage.Events.Clicked.OnServerEvent:Connect(function(plr,plrmouse)
	whichsquare(plrmouse)
end)

I've probably got some useless stuff I've made while trying to create this.

1 comment

2

Mouse instance is created locally and you don't need it server side.

1 answer

It looks to me like you're trying to pass the local player's mouse to the server. The server can not interact with the mouse object whatsoever. I'm not sure what you're trying to do here but a possible alternative is passing the object the mouse is targeting.

I hope my answer solved your problem. If you feel that this answer was best, please don't forget to mark it correct!

This discussion is preserved as it was. New answers, comments, and votes are closed.