I want to attach a attachment to a players arm to whoever clicks this certain click detector. How do i get the players character who clicks it?
1 Like
The MouseClick event fires with the player who clicked it. Access the Character property from it:
local clickDetector = script.Parent
local function onClick(player)
print(player.Character:GetFullName())
end
clickDetector.MouseClick:Connect(onClick)
7 Likes
local clickDetector = script.Parent
clickDetector.MouseClick:Connect(function(player)
local character = player.Character
if character then
local leftArm = character:WaitForChild("Left Arm")
if leftArm then
local attach = Instance.new("Attachment")
attach.Parent = leftArm
--change other properties of attachment here
end
end
end)
https://developer.roblox.com/en-us/api-reference/event/ClickDetector/MouseClick
Put this script into your ClickDetector
local ClickDetector = script.Parent
ClickDetector.MouseClick:Connect(function(player)
-- Checks if player touched it
if player:FindFirstChild("Humanoid") then
print(Humanoid.Parent.Name)
end
-- Checks if player touched it, but by an avatar item
if player.Parent:FindFirstChild("Humanoid") then
print(Humanoid.Parent.Name)
end
end)