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.
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.
@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)
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…
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.
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.