How do I make Players a choice to choose

So,Idk if I made it clear or not,so basically I wanna make an admin GUI and I’m having a problem making players a choice,so basically most people love to type their target’s name to kill instead of clicking the leaderboard tye of thing and thats what I wanna do,heres the script

kill.MouseButton1Click:Connect(function()

rs.KillPlayer:FireServer(player.MouseButton1Click)

end)

rs=Replicated Storage
kill=The button to kill

3 Likes

You need to use a LocalScript for the client side and a Server script for the server side (serverscriptservice).
You can try to use something like this:

LocalScript:

local repStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local Event = game:GetService("KillPlayer") -- you can also use just an event for all the commands

local killBtn = -- kill button
local targetTB = -- a textbox?

killBtn.MouseButton1Click:Connect(function()
    if players:FindFirstChild(targetTB.Text) then --check for the player
        Event:FireServer(targetTB.Text)
    else
        targetTB.Text = "Invalid name"
    end
end)

Script:

local repStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local Event = game:GetService("KillPlayer")

Event.OnServerEvent:Connect(function(plr, targetName)
    local target = FindFirstChild(targetTB.Text)
    if target then --check for the player (again cuz the check on the client is bypassable with exploits)
        -- Your script to kill here (target is the player to kill)
        print(plr.Name .. " killed " .. target.Name)
    end
end)

as seen on the picture,I want to click the player name instead of typing their name ( the boxes below output is the leaderboard for the names and they’re buttons to click on)

here’s me testing it

Ok, then you can use the script i posted before but you need to add a update function and a select one.

local list = -- scrolling frame
local target = ""

for _, v in pairs(list:GetChildren()) do
     if v:IsA("TextButton") then
         v.MouseButton1Click:Connect(function()
             target = v.Text
         end)
     end
end

You can use this to select the target, then use the other script to sent it to the server when the player press kill, just replace targetTB with target and remove .Text

do you need the update function too?

what is an update function?
btw,so I post this script to SSS and the one before to the client side? (and ye what is client)
sorry if im annoying cuz im a new dev

Put this as a local script in your gui:

local repStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local Event = repStorage:WaitForChild("KillPlayer") -- you can also use just an event for all the commands

local list = -- your list
local killBtn = -- kill button
local target = ""

killBtn.MouseButton1Click:Connect(function()
    if players:FindFirstChild(target) then --check for the player
        Event:FireServer(target)
    else
        print("invalid name")
    end
end)

for _, v in pairs(list:GetChildren()) do
     if v:IsA("TextButton") then
         v.MouseButton1Click:Connect(function()
             target = v.Text
         end)
     end
end

And this on a script on the serverscriptservice:

local repStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local Event = repStorage:WaitForChild("KillPlayer")

Event.OnServerEvent:Connect(function(plr, targetName)
    local target = players:FindFirstChild(targetName) -- edited here
    if target then --check for the player (again cuz the check on the client is bypassable with exploits)
        -- Your script to kill here (target is the player to kill)
        print(plr.Name .. " killed " .. targetName) -- edited here
    end
end)

Do you need a script to load the list or you already have it?

I believe I have it already,here’s to confirm it’s correct although I’ve already tested it.

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)


local plrs = game.Players

local serverMax = plrs.MaxPlayers


local template = game.ReplicatedStorage.Template

local list = script.Parent.List


for i = 0, serverMax do
	
	
	local label = template:Clone()
	
	label.Name = i
	
	label.Position = UDim2.new(0.027, 0, i * template.Size.Y.Scale, 0)
	label.Parent = list.TextButton
end


while wait() do
	
	
	for i, label in pairs(list:GetChildren()) do
		
		
		if plrs:GetChildren()[i] then
			
			
			label.Text = plrs:GetChildren()[i].Name
			
		else
			
			label.Text = ""
		end
	end
end

Yes this script might be fine.

local Event = game:GetService(“KillPlayer”)–W013:Unknown Type "KillPlayer’
I have ‘KillPlayer’ as RemoteEvent in Replicated Storage,did I do it wrong?

ops, my error

replace it with:

local Event = repStorage:WaitForChild("KillPlayer")

make sure to replace it in the local script and in the server script, or just copy again the script i posted before, i updated it

 if target then --check for the player (again cuz the check on the client is bypassable with exploits)
        -- Your script to kill here (target is the player to kill)

do I have to edit/add anything here according to your remarks?

You just need to replace this:

-- Your script to kill here (target is the player to kill)

With the kill code

k I’ll try

btw,ServerScriptService.Kill:7: attempt to call a nil value

Line 7: local target = FindFirstChild(List.Text)

local target = FindFirstChild(List.Text)
	if target then --check for the player (again cuz the check on the client is bypassable with exploits)
		
		local function kill_player(player)

			player.Character.Humanoid.Health = 0

		end -- Your script to kill here (target is the player to kill)
		
		print(plr.Name .. " killed " .. target.Name)
	end
end)

this?

try this now

local repStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local Event = repStorage:WaitForChild("KillPlayer")

Event.OnServerEvent:Connect(function(plr, targetName)
    local target = players:FindFirstChild(targetName) --edited here
    if target then --check for the player (again cuz the check on the client is bypassable with exploits)
        -- Your script to kill here (target is the player to kill)
        print(plr.Name .. " killed " .. targetName) -- edited here
    end
end)
local repStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local Event = repStorage:WaitForChild("Commands")
local List = game.StarterGui.Admin2.Commands.List.TextButton

Event.OnServerEvent:Connect(function(plr, targetName)
	local target = FindFirstChild(targetName)
	if target then --check for the player (again cuz the check on the client is bypassable with exploits)
		
		local function kill_player(player)

			player.Character.Humanoid.Health = 0

		end -- Your script to kill here (target is the player to kill)
		
		print(plr.Name .. " killed " .. targetName)
	end
end)

use this:

local char = plr.Character
if char then
    local hum = char:FindFirstChildOfClass("Humanoid")
    if hum then
        hum.Health = 0
    end
end

local target = FindFirstChild(targetName)
W001:Unknown Global ‘FindFirstChild’

replace it with this:

local target = players:FindFirstChild(targetName) 

sorry im stupid today

TY it worked!
But now I wanna make it so I know what I picked (If I click the action/player the background turns to a different colour and only one is will appear different(one at a time))
here’s my script:

local Players = script.Parent.Commands.List.TextButton
Players.MouseButton1Click.BackgroundColor3"252,49,60"

Edit:Hope the script helped me on explaining