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
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)
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
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
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
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?
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)
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)
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"