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

How do I make a GUI that you can enter a name and it will get the player?

Asked by 5 years ago
Edited 5 years ago

So I have a GUI that if you enter a name and click a Text Button, it will the kill the person whose name you typed in. Here is my code:

script.Parent.Activated:Connect(function()

for i,v in      pairs(game.Players.LocalPlayer(script.Parent.Parent.person))
do

v.Character:BreakJoints()

end

end)

The text button and all that works but it does not get the player to kill. How can I fix this??

2 answers

Log in to vote
1
Answered by 5 years ago

add a remote event in replicated Storage; then do this

-- from a local script of the player that will type the person to kill

local textBox =  -- put here the directory of the textBox where the player types the name of player to kill
local remoteEvent = --put the directory of where the remote event in replicated storage is
textBox.FocusLost:Connect(function() 
    remoteEvent:FireServer(textBox.Text)
end)

the above code listens for when the player's cursor stops focusing on the textbox and fires the remote event to let the server know the player to kill. however, if you want the player to click a button then the server is alerted of who to kill then change textBox.FocusLost to

[directory of the button to press].MouseButton1Click

and that should do it, and dont forget to remove the brackets too

-- in server script

local remoteEvent = --put the directory of where the remote event in replicated storage is
remoteEvent.OnServerEvent:Connect(function(player,toKill)
    for i, plr in pairs(game.Players:GetChildren()) do
        if plr.Name == toKill then
            plr.Character.Humanoid.Health = plr.Character.Humanoid.Health - plr.Character.Humanoid.MaxHealth
        end
    end
end)
0
Instead of FocusLost why not use InputEnded CjayPlyz 643 — 5y
0
that works too cjay User#23252 26 — 5y
Ad
Log in to vote
2
Answered by
CjayPlyz 643 Moderation Voter
5 years ago

-Insert a RemoteEvent in the ReplicatedStorage named "RemoteEvent1" and another one named "RemoteEvent2", and a Script in the ServerScriptService. Insert the LocalScript inside the TextBox and another in the TextButton.

--Script in ServerScriptService.

local RemoteEvent1 = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent1")
local RemoteEvent2 = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent2")
local Players = game:GetService("Players")

local function OnServerEvent1 (Player, Text)
    Player.PlayerGui.ScreenGui.TextBox.Text = Text
    --Change the ".ScreenGui.TextBox.Text" to the place where the textbox is.
end

local function OnServerEvent2 (Player, Text)
    local Player = Players[Text] --Finds the Player
    if Player then --Making sure that the Player exists.
        local Character = Player.Character
        if Character then --Making sure that the Character exists
            Character:BreakJoints() --Killing the Character.
        end
    end
end

RemoteEvent1:Connect(OnServerEvent1)
RemoteEvent2:Connect(OnServerEvent2)

--LocalScript in TextBox.

local RemoteEvent1 = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent1")

local function InputEnded ()
    local Text = script.Parent.Text
    RemoteEvent1:FireServer(Text)
end

script.Parent.InputEnded:Connect(InputEnded)

--LocalScript in TextButton.

local RemoteEvent2 = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent2")
local function MouseButton1Click ()

local Text = script.Parent.Parent.TextBox.Text --You might want to change this.
    RemoteEvent2:FireServer(Text)
end

script.Parent.MouseButton1Click:Connect(MouseButton1Click)
1
I tried my best to shorten the script ;P CjayPlyz 643 — 5y

Answer this question