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

How to get Humanoid when clicked on player using UserInputService?

Is there a way to get the humanoid when I clicked on the player by using UserInputService? Something like this: local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.Button1Down:Connect(function() if Mouse.Target.Parent:FindFirstChild("Humanoid") then print(Mouse.Target.Parent.Name) end end)

But use UserInputService instead, Thanks in advance ^.^

2 comments

0

Why do you need to use UserInputService exactly?

0

@AddisonAvery I'm trying to get the player name when user click on the other player in order to create a single target skill. And I'm not allowed to use GetMouse()

1 answer

Well, actually its kind of useless because the only instance in the game that has a mouse is the Player

But if you want it in the parameter then its reasonable

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

local function CheckPlayer()
	Mouse.Button1Down:Connect(function(player)
		if player.AccountAge == 2006 then
			print("You are a roblox veteran")
		end
	end)
end

Hope you understand..

If you want UserInputService then

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gameProcessed) -- Puts input as the paramater
	if input.KeyCode == Enum.KeyCode.Q then -- Remember its KeyCode not Keycode
		print("You pressed Q")
		-- Do whatever you want
	end
end)


I know this has got nothing with your answer but there is something called InputEnded InputEnded basically fires something when the player lets go of the key Lets try again


local UIS = game:GetService("UserInputService")

local IsPlayerHoldingKey = false

UIS.InputBegan:Connect(function(input, gameProcessed) -- Puts input as the paramater
	if input.KeyCode == Enum.KeyCode.Q then -- Remember its KeyCode not Keycode
		IsPlayerHoldingKey = true
		-- Do whatever you want
		
		while IsPlayerHoldingKey do
			wait()
			print("Player is holding down the A Key")
		end
	end
	
	UIS.InputEnded:Connect(function(input, gameProcessed)
		if input.KeyCode == Enum.KeyCode.Q then
			IsPlayerHoldingKey = false
		end
	end)
end)

So that script detects if the player is holding the key and while they are holding it down it will run that function

If there are any questions please consider commenting

2 comments

0

Ohh i see, i'm trying to get the player name when user click on the other player in order to create a single target skill that will be sent to the server. But maybe I should create a part to get a touch part instead. Thanks you so much for your attention sir ^.^

0

No problem man, i can tell you will become a professional scripter ;)

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