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

How do I find the names of the players in the server then put their names in the name of a brick?

Asked by 8 years ago

So, How do I find the names of each player in the server, then place their names in the name of a different brick each?

Yup, pretty confusing, for example, there are two players on the server, bob and bill. I want to put 'bill' in the name of brick 1, and I also want to put 'bob' in the name of brick 2.

And both of those bricks are supposed to kill their player when they're clicked.

(The killing script, i just need help editing it to find the player who it's going to kill.)

function onClicked(playerWhoTouched) workspace.IAmSoloz.Humanoid.Health = 0 end script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
0
Answered by 8 years ago

First, you'd need to get the names first. Depending if you have filtering enabled on, it could be different, but I'll just say it the filtering enabled way.

You'll need a local script, and a server script.

Here's the script, and I'll comment along the way on what each part means.

local debouce = false
local rEvent = Instance.new("RemoteEvent", game.ReplicatedStorage) -- To communicate between server and client.
rEvent.Name = "rEvent"

game.Players.PlayerAdded:connect(function(plr)
    if not debounce then
        debounce = true
        local brick = Instance.new("Part", game.Workspace)
        local clickDetect = Instance.new("ClickDetector", brick)
        brick.Name = plr.Name -- Making the brick, so then the client can find it.
        rEvent:FireClient(plr) -- Fire the client of the player with remote event for communicating if the brick got clicked or not.
        debouce = false
    end
end)

Then for the local script, you're just going to have something like

local plr = game.Players.LocalPlayer
local char = plr.Character 

game.ReplicatedStorage.rEvent.OnClientEvent:connect(function()
    game.Workspace:findFirstChild(plr.Name).ClickDetector:MouseButton1Click:connect(function()
    char.Humanoid:TakeDamage(100)
    end)
end)

Keep in mind I'm a beginner as well, so this very well could not work. You've been warned.

Hope this works anyways, and good luck!

0
This script works! However, the brick needs to spawn in a very specific area, and this script is way too complicated for me so how would I add a location for it to spawn? IAmSoloz 14 — 8y
Ad

Answer this question