Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

2 comments

0

Thx

0

np

This discussion is preserved as it was. New answers, comments, and votes are closed.