Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can you find a target's humanoid with target mouse in a serverscript?

Asked by 5 years ago

This might not be the good place to post this but I don't know how I would find a targerts humanoidsrootpart, any suggestions?

For example for such code

1local humanoidRootPart = Player.Character.HumanoidRootPart
2       local targetRootPart = (I am stuck here).HumanoidRootPart

Thanks

1 answer

Log in to vote
0
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:

01local Players = game:GetService("Players")
02local UserInputService = game:GetService("UserInputService")
03local localPlayer = Players.LocalPlayer
04local mouse = localPlayer:GetMouse()
05 
06local function inputBegan(input, gameProcessed)
07    if input.UserInputType == Enum.UserInputType.MouseButton1 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
10 
11            local huamonidRootPart = targetCharacter:WaitForChild("HumanoidRootPart") -- Got the HumanoidRootPart.
12        end
13    end
14end
15 
16UserInputService.InputBegan:Connect(inputBegan)

Note that this only works for a player's character, not NPC's.

0
Thx 3dwardIsBack -10 — 5y
0
np youtubemasterWOW 2741 — 5y
Ad

Answer this question