Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

8 comments

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

0

Repost this question or just edit this question with the new code so I can see.

0

There, I edited it

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.

0

can you give an example of making it a variable and checking if it returned anything?

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

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?

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

This discussion is preserved as it was. New answers, comments, and votes are closed.