TextBox Event Help

So I have a problem where this doesn’t run:

game.Players.PlayerAdded:Connect(function(plr)
	plr.PlayerGui:WaitForChild("Test").TextBox.Focused:Connect(function()
		local newPart = Instance.new("Part")
		newPart.Name = plr.Name
		newPart.Parent = game.Workspace
	end)
end)

But when I change the event to something like MouseEnter it works fine. Does anyone have an idea why?

It’s basically supposed to create a part whenever the event is fired.

Hello!

I’ve made a place that works! It’s a little different than what you’ve created.
It uses Remote events.

Baseplate.rbxl (21.1 KB)

1 Like

Thank you! I will check it out

I also just realized

I’m assuming that’s a server script. Server can’t get client’s input, that’s most likely your reason.

Plugging in here: if you’re using this from a LocalScript, it will not run as expected. LocalScripts run at a time when the player has already joined, so a LocalScript will not see when PlayerAdded is fired for the current client. Its use is unnecessary.

You can use the LocalPlayer variable as an alternative if you need to get the player. It is implicitly defined for LocalScripts.

local plr = game:GetService("Players").LocalPlayer

plr.PlayerGui -- so on

I was using a server-side script for that. But apparently Focused/FocusLost can only be run on local scripts.

Yeah, that’s what I said in the earlier post.