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

How can i add a click detector inside a players torso?

Hello there, ive been attempting to create a script that inserts a clickdetector into the players torso alowing other players to hover there mouses over the other players to view there name and if they click it will open up a trading gui.

I am here today asking how i can fix my script. I am only looking for a correction on the inserting portion. Here is what i have

game.Players.PlayerAdded:connect(function(plr)
local detector = Instance.new('ClickDetector', plr.Character.HumanoidRootPart)
detector.Name = "detector"
end)

Now, i was wondering if it would be more efficiant to clone one with a pre made script that open does the name and trading part. Or should i use instance.new.

Please fix my script and tell me wich way would br more efficiant. If i were to clone i would try this(clickdetector is in replicatedfirst with a premade script alowing it to open the trading gui when clicking the torso of another player)

local service = game:GetService('ReplicatedFirst')
game.Players.PlayerAdded:connect(function(plr)
service:FindFirstChild('ClickDetector'):Clone().Parent = plr.Character.HumanoidRootPart
end)

This way it would already have a script in it

Thank you for reading

1 comment

0

Use instance.new it is just as efficient as cloning the detector into the torso.

2 answers

I don't know how to locate the player's torso using the PlayerAdded thing but I know how to do it when the player touches a block. Wherever the player spawns, make a cancollide=false and transparent part. Insert this script (I tested it):

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not hit.Parent.UpperTorso:FindFirstChild("ClickDetector") then
		local detector = Instance.new("ClickDetector", hit.Parent.UpperTorso)
	end
	end
	end)

Just use Instance.new() It's much easier.

game.Players.PlayerAdded:connect(function(plr)
wait(1.5)
local detector = Instance.new('ClickDetector')
detector.Parent = workspace[plr.Name].HumanoidRootPart
detector.Name = "detector"
end)

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