Hello, I am @Owen_Hevalide2 and I have a basic question to ask
How would i make it so when a player types in my TextBox it saves to the Value inside the Text Box, so i can access what they typed through a script, to run a function to kick that player! Can I have any advice? I have provided a image showing what i am trying to do!
If you don’t understand it i will explain it here:
When you type in the TextBox and save it, it will copy what they typed and make the Value’s value to the thing they typed. This will be used in a Admin Panel where you can kick users.
script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
script.Parent.Value.Value == script.Parent.Text
end)
local plr = game.Players:FindFirstChild(script.Parent.Value.Value)
for i,v in pairs(game.Players:GetChildren()) do
if v == plr.Name then
plr:Kick()
end
end
local player = game.Players[script.Parent.Text]
if player then
player:Kick("message")
end
this would prevent unnecessarily iterating and comparing each player (also your code would currently only compare a player object with a string instead of comparing the name, same with crusty’s code).
I suggest testing code to an extent too where possible before proposing it as a solution, to not confuse other developers.
I had no idea how I could set this up, and i could not see how to do this on the internet ( and any way to learn it ) so i asked on the DevForum, so i had no code.
Try to listen for the FocusLost event for the TextBox.
local StringValue = script.StringValue -- place a string value under this script, called StringValue
local Textbox = script.Parent -- place the LocalScript right under the text box
Textbox.FocusLost:Connect(function()
local text = Textbox.Text
if game.Players[text] then
game.Players[text]:Kick()
StringValue.Value = text -- each time focus was lost, set the value to the string value for whatever reason
end
end)