Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

0
Use instance.new it is just as efficient as cloning the detector into the torso. martingalethreat 81 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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)
Ad
Log in to vote
0
Answered by
xEiffel 280 Moderation Voter
6 years ago

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)

Answer this question