I’m making a script where you can click a player and it gives information about the person’s game stats., the problem is that I can’t figure out how I’ve made a script that puts a ClickDetector in the person’s body parts but the script doesn’t work if anybody could help fix it, it would be appreciated!
The Script:
game.Players.PlayerAdded:Connect(function(player)
for i, v in pairs(game.Workspace[player.Name]:GetChildren()) do
local click = Instance.new("ClickDetector")
click.Parent = game.Workspace[player.Name][v.Name]
end
end)
You dont need to put a click detector inside someones body. You can simply use a local script > and use userinputservice. Roblox wiki has an example of how to use this.
local UserInputService = game:GetService("UserInputService")
-- A sample function providing one usage of InputBegan
local function onInputBegan(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("The left mouse button has been pressed!")
end
end
UserInputService.InputBegan:Connect(onInputBegan)
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
function showStats(player)
--Show
end
mouse.Button1Down:Connect(function()
if not mouse.Target then return end
local player = game.Players:GetPlayerFromCharacter(mouse.Target.Parent)
if player then
showStats(player)
end
end)