How to detect a click on a local script and give animation to the person who clicked on a script?

hi i need help i don’t know how to make a local script detect a click and send it to a script where it gives animation to the person who clicked

1 Like

im assuming you mean everytime you click anywhere on the screen it will make the player play an animation. to do that, follow these steps:

  1. create a remote event in replicatedstorage called "PlayAnimOnClick
  2. make a local script in StarterPlayerScripts and copy the following code into it:
local mouse = game.Players.LocalPlayer

mouse.Button1Down:Connect(function()
    game.ReplicatedStorage.PlayAnimOnClick:FireServer()
end)
  1. create a script in serverscriptservice and copy the following code into it:
game.ReplicatedStorage.PlayAnimOnClick.OnServerEvent:Connect(function(plr)
    -- do your animation stuff here
end)
1 Like

doesnt work

Button1Down is not a valid member of Player “Players.jorgasogameplays”

I think Faze meant to use player:GetMouse().

That being said, you shouldn’t use GetMouse anymore and it has been superceded by UserInputService.

I think this might work, can’t test it ATM:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("The left mouse button has been pressed!")
        -- Or you can fire the remote event
        game.ReplicatedStorage.PlayAnimOnClick:FireServer()
	end
end)

Replace the print statement with what you want to do on click.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.