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 4 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

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

Thanks

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 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:

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()

local function inputBegan(input, gameProcessed)
    if input.UserInputType == Enum.UserInputType.MouseButton1 and mouse.Target.Parent ~= localPlayer.Character then
        if Players:GetPlayerFromCharacter(mouse.Target.Parent) or mouse.Target.Parent:FindFirstChild("Humanoid") then
            local targetCharacter = mouse.Target.Parent

            local huamonidRootPart = targetCharacter:WaitForChild("HumanoidRootPart") -- Got the HumanoidRootPart.
        end
    end
end

UserInputService.InputBegan:Connect(inputBegan)

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

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

Answer this question