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

How to set a value to what the text on a text box is (Filtering Enabled)?

Asked by
soutpansa 120
5 years ago
Edited 5 years ago

I've got an admin gui in my game, admins have to type a players name in, then press confirm to set that player as the one that is affected. The issue is that in filtering enabled, I don't know how to set the player value to what the text is. This is what I tried:

script.ConfirmPlayer.OnServerEvent:Connect(function(Player)
    if Player.Name == "soutpansa" or Player.Name == "WakaFlockajr" or Player.Name == "Night_Moons" 
        or Player.Name == "bigbus92" or Player.Name == "Shirou_XI" then
        script.PlayerValue.Value = Player.PlayerGui.MainHud.ControlPanel.Person.Text
    end
end)

A local script fires the event from the gui. I'm not sure what else to try here in order to set the PlayerValue.

Thanks for reading

Edit: Server script:

local DoPlayer = script.ConfirmPlayer

function DoPlayer.OnServerInvoke(Player)
    if Player.Name == "soutpansa" or Player.Name == "WakaFlockajr" or Player.Name == "Night_Moons" 
        or Player.Name == "bigbus92" or Player.Name == "Shirou_XI" then
        script.PlayerValue.Value = Player:FindFirstChild("PlayerGui"):FindFirstChild("MainHud").ControlPanel.Person.Text
    end
end

(I know im supposed to return something here, but idk what)

local script:

wait(1)
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local Name = script.Parent.Parent.Person.Text
    Player.Backpack.Control_Panel.ConfirmPlayer:InvokeServer()
end)

1 answer

Log in to vote
1
Answered by 5 years ago

You cannot access a PlayerGui using a server script on the server. Instead, you could just either fire another RemoteEvent or you can use RemoteFunctions to retrieve the text of the client and then return the text which then you can set the value of 'script.PlayerValue.Value' to that.

Here is a helpful article on this: http://robloxdev.com/articles/Remote-Functions-and-Events

0
While using a RemoteFunction, I get the error: "attempt to index a nil value" (line 7, which is script.PlayerValue.Value = Player:FindFirstChild("PlayerGui"):FindFirstChild("MainHud").ControlPanel.Person.Text soutpansa 120 — 5y
0
Repost this question or just edit this question with the new code so I can see. YabaDabaD0O 505 — 5y
0
There, I edited it soutpansa 120 — 5y
0
On line 4, instead of doing all that just do 'return Player:FindFirstChild("PlayerGui"):FindFirstChild("MainHud").ControlPanel.Person.Text' then in the local script on the line where you invoke the server, make it a variable and add an if statement to see if the RemoteFunction returns a value, which in this case is the Text, and set the value of 'PlayerValue' to the variable where you invoked it. YabaDabaD0O 505 — 5y
View all comments (4 more)
0
can you give an example of making it a variable and checking if it returned anything? soutpansa 120 — 5y
0
I didn't test this before-hand but it should be sufficient enough for an example. --CLIENT-- local var = remoteFunction:InvokeServer() if var then print(var.Value) end --SERVER -- function getData.OnServerInvoke(player) local data = workspace:FindFirstChild(player.Name).Humanoid.Health return data end YabaDabaD0O 505 — 5y
0
Sorry for the late response. But I still get the error: "attempt to index a nil value" on the same line. How about firing another remote event? How would I go about making it work like t hat? soutpansa 120 — 5y
0
Nevermind, I got it to work. Instead of returning anything, I passed Name through the function. Name = script.Parent.Parent.Person.Text. local var = Player.Backpack.Control_Panel.ConfirmPlayer:InvokeServer(Name). Now it works fine on the actual game. Thanks for your help soutpansa 120 — 5y
Ad

Answer this question