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

How would I allow the player to be able to click on other players?

I have made a script where you can click on other players and then a function fires. I'm still new to scripting so there might be a way to do this that I just haven't learned yet.

In my game, I have already inserted a ClickDetector on every players Character. I made a Local Script in StarterGui that reacts to when you click on the player. However, I'm not sure how to get it to click on an array of objects. I tried using this script to fix the problem:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Human = game.Workspace:GetChildren()

if Human.ClickDetector ~= nil then
	Human.ClickDetector.MouseClick:connect(function(player)
		print "clicked on a player"
	end)
end

However, this doesn't make the ClickDetector respond. The function works when I make a specific name for the variable, but not when the variable is an array of objects. How can I get this to work when clicked on any player with a ClickDetector in their character?

1 answer

✓ Accepted answer

###No. You would have to make a click detector on CharacterAdded.

###Server script in ServerScriptService

game:GetService("Players").PlayerAdded:Connect(function(player)

    player.CharacterAdded:Connect(function(char)
        local clickDetector = Instance.new("ClickDetector")
        clickDetector.Parent = char
        clickDetector.MouseClick:Connect(function()
            print("clicked on:", player)
        end)

    end)
end)

3 comments

0

Thanks, but is there any way to connect this to a LocalScript? Because I have a GUI pop up when the players are clicked, that's why I was using a LocalScript

1

Make a RemoteEvent and use FireClient

0

Thank you!

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