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

How could I find the names of an ingame player, then rename a brick the name of the player?

So I want to create a brick that finds a player, then when it's clicked it kills that player. But the thing is I want multiple of those kill bricks that altogether will kill every player, but so that the player clicking the blocks doesnt just randomly kill people, how would I also change the name of the brick?

SUMMARY: I want to make a brick, that kills a certain player in the server, but also renames itself to the name of the player it will kill.

For example : function onClicked(playerWhoTouched) workspace.[insert name here].Humanoid.Health = 0 end script.Parent.ClickDetector.MouseClick:connect(onClicked)

But how would I find the name in the first place?

3 answers

A ClickDetector's MouseClick event passes the Player instance of the player who clicked as first parameter to a connected callback function.

local button = script.Parent

button.ClickDetector.MouseClick:connect(function(player)
	button.Name = "Kill " .. player.Name
	
	local character = player.Character
	
	if character then
		local humanoid = character:FindFirstChild("Humanoid")
		
		if humanoid then
			humanoid.Health = 0
		end
	end
end)

If you want to rename the button prior to killing the player, then you will have to get the player's Player instance differently.

2 comments

0

In layman's terms: MouseClick gives you the player who clicked, so use that.

0

Thank you so much for this! but I need to find the name before hand.

Sorry, if you read the rules this is to help people with scripts and not make requests.

3 comments

0

I AM NOT MAKING A REQUEST.

2

You shouldn't be writing an answer to say that... Use comments.

0

Well, considering you can't use comments because of your rep, just don't post answers like this.

script.Parent.ClickDetector.MouseClick:connect(function(playerWhoClicked) playerWhoClicked.Humanoid.Health = 0 script.Parent.Name = playerWhoClicked.Name end)

A simple script to find and kill on click. You can beef it up yourself.

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