Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago
Edited 8 years ago

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

Log in to vote
3
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago
Edited 8 years ago

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.

0
In layman's terms: MouseClick gives you the player who clicked, so use that. Perci1 4988 — 8y
0
Thank you so much for this! but I need to find the name before hand. IAmSoloz 14 — 8y
Ad
Log in to vote
-2
Answered by 8 years ago

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

0
I AM NOT MAKING A REQUEST. IAmSoloz 14 — 8y
2
You shouldn't be writing an answer to say that... Use comments. Link150 1355 — 8y
0
Well, considering you can't use comments because of your rep, just don't post answers like this. User#11440 120 — 8y
Log in to vote
-4
Answered by 8 years ago

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.

Answer this question