Can I use GetMouse() without LocalScript?

local players = game:GetService("Players")
local name = script.Parent:WaitForChild("Humanoid").Parent.Name
local localplayer = players:WaitForChild(name)
local mouse = localplayer:GetMouse()

I need to play an animation when the mouse is clicked but it only plays in the client when I use a localscript.

just telling me about remote events is enough but

THANKS EVERYONE!!! :))

1 Like

I dont think you can. The mouse is a client side object.

1 Like

Use RemoteEvent

1 Like

Well, just as @ryanhawari17 said, you can use RemoteEvents to trigger a function from client in a server. When the mouse is clicked, you can fire the remote event to server and play sound on server. About the looped for others, you can just set looped to false on server before playing the sound. I hope I am helpful.

1 Like

Use remote event, I can help you if you need some.

1 Like

@ryanhawari17 @stivensigalcrasaft
You can pass a mouse object to the server, but since it’s the server, it can not detect any inputs from the client (unless you are talking about passing values from a mouse event)

1 Like

You can easily do it with this:

Insert a RemoteEvent called PlayerMouse in ReplicatedStorage.

Client:

local Player = game:GetService("Players").LocalPlayer

local Mouse = Player:GetMouse()

game:GetService("ReplicatedStorage").PlayerMouse:FireServer(Mouse)

Server:

game:GetService("ReplicatedStorage").PlayerMouse.OnServerEvent:Connect(function(Player, Mouse)
-- Do whatever with Mouse here
end)

Not sure why you would want to do this, but ok I guess…

1 Like

I’m pretty sure you can’t. Mouse is a client - sided object and when we pass an object in a remote event, we’re only passing a reference, and because the object doesn’t exist on the server, it’s equal to nil.

1 Like

This is what i actually mean to use RemoteEvent

That doesn’t work. The Mouse object will be equal to nil on the server.

1 Like

From my experience, it does pass the mouse object, printing it prints “Mouse”. Although any inputs wont be detected.

Hmm, I’ve tried it a few months before and it didn’t work. Maybe I’ve done something differently

Oh, that’s weird. I’ve helped someone who tried to give the mouse object to the server, and they said it printed “Mouse”. I also copied their code and it did print mouse. This was tested on VSB btw so either VSB is different or there was something in his code that did that.

1 Like