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:

01script.Parent.Activated:Connect(function()
02 
03for i,v in      pairs(game.Players.LocalPlayer(script.Parent.Parent.person))
04do
05 
06v.Character:BreakJoints()
07 
08end
09 
10end)

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

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

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

1[directory of the button to press].MouseButton1Click

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

in server script

1local remoteEvent = --put the directory of where the remote event in replicated storage is
2remoteEvent.OnServerEvent:Connect(function(player,toKill)
3    for i, plr in pairs(game.Players:GetChildren()) do
4        if plr.Name == toKill then
5            plr.Character.Humanoid.Health = plr.Character.Humanoid.Health - plr.Character.Humanoid.MaxHealth
6        end
7    end
8end)
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.

01local RemoteEvent1 = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent1")
02local RemoteEvent2 = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent2")
03local Players = game:GetService("Players")
04 
05local function OnServerEvent1 (Player, Text)
06    Player.PlayerGui.ScreenGui.TextBox.Text = Text
07    --Change the ".ScreenGui.TextBox.Text" to the place where the textbox is.
08end
09 
10local function OnServerEvent2 (Player, Text)
11    local Player = Players[Text] --Finds the Player
12    if Player then --Making sure that the Player exists.
13        local Character = Player.Character
14        if Character then --Making sure that the Character exists
15            Character:BreakJoints() --Killing the Character.
16        end
17    end
18end
19 
20RemoteEvent1:Connect(OnServerEvent1)
21RemoteEvent2:Connect(OnServerEvent2)

–LocalScript in TextBox.

1local RemoteEvent1 = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent1")
2 
3local function InputEnded ()
4    local Text = script.Parent.Text
5    RemoteEvent1:FireServer(Text)
6end
7 
8script.Parent.InputEnded:Connect(InputEnded)

–LocalScript in TextButton.

1local RemoteEvent2 = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent2")
2local function MouseButton1Click ()
3 
4local Text = script.Parent.Parent.TextBox.Text --You might want to change this.
5    RemoteEvent2:FireServer(Text)
6end
7 
8script.Parent.MouseButton1Click:Connect(MouseButton1Click)
1
I tried my best to shorten the script ;P CjayPlyz 643 — 5y

Answer this question