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

Humanoid Touch to Click Detector?

Hello,

After all of my desperate attempts to make this work, it hasn't been lol. I made a script for a key where if the humanoid touches the key, it is picked up. It will work better for my game if it is picked up if it is clicked. Any help? I will link the script below.

local key = script.Parent:WaitForChild('KeyUnion')
local weld = nil

key.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			if game.Players:GetPlayerFromCharacter(hit.Parent).Team.Name == 'Safe' and key:IsDescendantOf(workspace) and key.Parent.Parent:FindFirstChild('Humanoid') == nil then				
				key.Parent.Parent = game.Players:GetPlayerFromCharacter(hit.Parent).Backpack
				print('hey')
			end
		end
	end
end)

script.Parent.Equipped:Connect(function()
	weld = Instance.new('Weld')
	weld.Part0 = script.Parent.Parent["Right Arm"]
	weld.Part1 = key
	weld.C0 = CFrame.new(0, -1, 0) * CFrame.Angles(-0.5 * math.pi, 0, 0)
	weld.C1 = script.Parent.Grip
	weld.Parent = script.Parent.Parent['Right Arm']
end)

script.Parent.Unequipped:Connect(function()
	if weld ~= nil then
		weld:Destroy()
		weld = nil
	end
end)

Thank you in advance.

1 comment

0

Try using ClickDetectors if you want it to be clicked by something. It could be useful to be able to click and touch the key(because tapping on objects is really difficult on mobile)

1 answer

If you use the Roblox Mouse https://wiki.roblox.com/index.php?title=API:Class/Mouse, you are able to access Mouse.Hit as well as Mouse.Target. What you would want to do is create a Local Script where you get the Mouse from the player, and then set up a MouseButton1Down (or Up for full click), and then when that fires you get the Mouse.Hit (or Target), and test to see if that is the key. If so, then you would fire a RemoteEvent across to the Server telling it that the Client has clicked on the key. The server can then destroy the key while the client records that the player has obtained it.

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