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

I'm having a problem with click detectors in characters?

Hello helpers!

I'm having a bit of trouble with my Roblox Lua at the moment. I am trying to create a feature that enables the user to click and select another player.So far, the only way I can see of doing this is a clickDetector and a remote event. (With filtering enabled)

The Scripts are being placed as so:

->StarterCharacterScripts
	->playerClickDetector
	->LocalScript				(Used to FireServer() when detector is clicked)
	->Script					(Runs the function on click)

localScript:

clickDetector = script.Parent:WaitForChild("playerClickDetector");
local myplayerName = script.Parent.Name;
clickDetector.MouseClick:connect(function(player)
	print("clicked");
	game.Workspace.playerClicked:FireServer(player, myplayerName);
end)

Script

local targetPlayer;
local targetPlayerName;
local targetPlayerHealth;
 

game.Workspace:WaitForChild("playerClicked").OnServerEvent:connect(function(player, playerName)
	print(player.Name);
		print(playerName);

end)

If you could help me I would be extremely grateful! I am still looking for a solution, and "trial and error'ing" anything I can think of.

All the best, Ciarán =)

1 comment

0

the click detector should be in the player's character

1 answer

I found a solution using raycasting, if anyone has any similar problems and would like to see my code, feel free to pop me a message!

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