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

How do you call on the players mouse VIA a PLR variable in a ServerScript?

I have been working on a ServerScript thats inside a part named "Handle", and the handle is inside a tool (the tool being in StarterPack). I made the script a ServerScript because the game is FilteringEnabled. Here's the code:

tool = script.Parent.Parent
hand = script.Parent
LOADED = 1
plr = script.Parent.Parent.Parent.Parent
m = plr:GetMouse()
toole = false

tool.Equipped:connect(function()
	tool = true
end)

tool.Unequipped:connect(function()
	tool = false
end)

m.Button1Down:connect(function()
	if LOADED == 1 and tool == true then
		LOADED = LOADED - 1
		script.Sound:Play()
		a = plr.Character.Humanoid:LoadAnimation(script.Animation)
		a:Play()
		wait(0.8)
		LOADED = LOADED + 1
	end
end)

m.KeyDown:connect(function(key)
	key = key:lower()
	if key == "q" and LOADED == 1 and tool == true then
		LOADED = LOADED - 1
		script.ignite:play()
		local pe = workspace.pepart2.ParticleEmitter:clone()
		pe.Parent = hand.Attachment
		local lite = Instance.new("PointLight",script.Parent.Attachment)
		wait(6.5)
		lite:remove()
		pe:remove()
		wait(3)
		LOADED = LOADED + 1
	end
end)

It works in studio, although when tested in a server, it stumbles upon an error, "attempt to index "m" (the mouse variable), a nil value.

I hope you guys can help me out, thanks!

1 answer

✓ Accepted answer

You can only access the mouse from a LocalScript - ie - from the client.

The solution to this is as follows:

-You have a server script, a local script and a RemoteEvent in the tool

-The local script listens for input

-When it gets input, it calls :FireServer on a RemoteEvent

-The server listens for the .OnServerEvent from the RemoteEvent

You may notice a slight delay due to the networking, but theres no other FE solution

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