You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want to make an Admin GUI with the ability to kill the player.
What is the issue? The script thinks the textbox has no text. (it does)
What solutions have you tried so far? I have tried to check if it has changed.
My code is below:
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.TextBox.Text == "" then
print("Nothing.")
else
workspace[script.Parent.Parent.TextBox.Text].Head:Destroy()
end
end)
There are a few issues with this code. Firstly, if you were to kill the subject from the admins client, nothing would happen as for it to be replicated (shown) to other players, you’ll have to do it from the server. To make it happen from the server, you’ll have to use a RemoteEvent, which you can find more about here
Secondly, workspace[directory] would only work if the players name was spelt correctly, and if it wasn’t it’d error. This is, however, a pretty inefficient way to kill the player and there are better ways of doing as such, like setting their health to 0, deleting their character, etc.
If you take this into consideration, your local script (client one) and script (server) should look like this:
-- Local script
local remote = REMOTE_DIRECTORY_HERE
local button = script.Parent
button.MouseButton1Click:Connect(function()
local text = button.Parent.TextBox.Text -- For ease of use/ access
if text == "" then
print("nothing")
else
local subject = game.Players:FindFirstChild(text) -- Sees if theres a player
if not subject then return false end -- if a player isn't found then end
remote:FireServer(subject)
end
end)
-- Server Script here
local remote = REMOTE_DIRECTORY_HERE
remote.OnServerEvent:Connect(function(plr, subject)
-- Any sort of sanity checks should be done here
local subChar = subject.Character or subject.CharacterAdded:Wait()
local subHum = subChar:FindFirstChild("Humanoid")
-- Now we can use any sort of killing method
subHum.Health = 0
subHum:Kill()
subChar:Destroy()
end)
The method they were previously using works fine, if anything using a while loop for this sort of situation would not only be inefficient due to polling but also cause errors and issues which can easily be avoided by using an event, as they have done now.
When you insert the name of the player from an output, take the name of the player and put it into a stringvalue value. then you can do the following: (Assuming this is a local script)