Answered by
5 years ago Edited 5 years ago
A ServerScript cannot get a player's mouse, therefore this would not work.
What you would have to do is insert a LocalScript into StarterPlayer > StarterPlayerScripts and insert the following code:
01 | local Players = game:GetService( "Players" ) |
02 | local UserInputService = game:GetService( "UserInputService" ) |
03 | local localPlayer = Players.LocalPlayer |
04 | local mouse = localPlayer:GetMouse() |
06 | local function inputBegan(input, gameProcessed) |
07 | if input.UserInputType = = Enum.UserInputType.MouseButton 1 and mouse.Target.Parent ~ = localPlayer.Character then |
08 | if Players:GetPlayerFromCharacter(mouse.Target.Parent) or mouse.Target.Parent:FindFirstChild( "Humanoid" ) then |
09 | local targetCharacter = mouse.Target.Parent |
11 | local huamonidRootPart = targetCharacter:WaitForChild( "HumanoidRootPart" ) |
16 | UserInputService.InputBegan:Connect(inputBegan) |
Note that this only works for a player's character, not NPC's.