Hi everyone, I’m using a TextBox and when a player’s name is typed in and entered, the RemoteEvent would fire and the server would try to find the player in the workspace. But I’m having trouble transferring the name of the player from the Local Script to the Server Script.
Local Script:
local UsernameBox = GUI.Frame.ArrestPage.Information.aUsername
local ReplicatedStorage = game:GetService("ReplicatedStorage")
UsernameBox.FocusLost:Connect(function()
local Username = UsernameBox.Text
if game.Workspace:WaitForChild(Username) then
ReplicatedStorage.ArrestSystem.Action:FireServer(Username)
end
end)
Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.ArrestSystem.Action.OnServerEvent:Connect(function(player, Username)
if (Username) then
local player = game.Workspace:WaitForChild(Username)
print(player)
end
end)```
You’re sending the data from the client to the server correctly.
I would verify the following:
Your local script runs (e.g. put a print statement in it)
The GUI object is under a PlayerGui and not under StarterGui (a common mistake, try printing GUI:IsDescendentOf(game:GetService("StarterGui"))
FocusLost is firing when intended (add a print statement inside)
The code inside the wait for child if statement is running (another print statement)
Similar things for the server code if nothing above is a problem
(Another note for your code, you might want to verify the child found in workspace is a character. I would recommend instead searching game:GetService("Players") then getting the character with Player.Character (e.g. if a player searches for PineTree and there is a model of a tree named PineTree.)
Hello, here’s how I would rewrite the code in the local script (I had this problem just yesterday lol). FocusLost returns two params, but only the first one is useful. It is ‘enterpressed : Boolean’
local UsernameBox = GUI.Frame.ArrestPage.Information.aUsername
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ep
repeat
ep = UsernameBox.FocusLost:Wait()
until
ep == true
local Username = UsernameBox.Text
if game.Workspace:FindFirstChild(Username) then
ReplicatedStorage.ArrestSystem.Action:FireServer(Username)
end
Server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.ArrestSystem.Action.OnServerEvent:Connect(function(player, Username)
if Username then
local player = game.Workspace:WaitForChild(Username)
print(player)
end
end)