How do you get text info from the client inside textboxes

Im having a problem with my textboxes not working, and Ive tried a few ways to solve it. None of the solutions ive come up with have worked even when I made sure they were done correctly. I may have just missed something and didnt notice or im doing it entirely wrong

I have 2 textboxes and a button, the first textbox is the player entering a username, and the second textbox is the player entering a number

Client

local Button = script.Parent
local player = game.Players.LocalPlayer
local KillGiveEvent = game.ReplicatedStorage.KillGiveEvent
local Name = Button.Parent.Name
local Kills = Button.Parent.Kills

Button.Activated:Connect(function()
	local Username = tostring(Name.Text)
	local KillCount = tonumber(Kills.Text)
	KillGiveEvent:FireServer(player, Username, KillCount)
end)

Server

local KillGiveEvent = game.ReplicatedStorage.KillGiveEvent
local groupId = 0 -- substitute number here

KillGiveEvent.OnServerEvent:Connect(function(player, Username, KillCount)
	local Target = game.Players:GetPlayerFromCharacter(Username) -- issue here being unable to get a string
	if player:IsInGroup(groupId) then
		if player:GetRankInGroup(groupId) >= 247 then
			Target:WaitForChild("KillsInfo"):WaitForChild("Killstreak").Value += KillCount -- issue being attempting to index nil with WaitForChild
		else
		end
	end
end)
2 Likes

GetPlayerFromCharacter(Username) - This won’t work, because Username is a string, but GetPlayerFromCharacter() expects a Model, Because of this, the variable “Target” is empty.
Use game.Players:FindFirstChild(Username) instead:

local Target = game.Players:FindFirstChild(Username)

Output says expects a string, but instance was passed on that line

mmmm yes.I reread the code.
You transmit the following on the server: player, target(username), KillCount
And on the server you get: Player, Player, Username, killCount
Because onServerEvent always returns the player on whose behalf the event was called as the first argument. As a result, you get the same player twice, with the first and second arguments.

I changed my fireserver to (Username, KillCount) and that fixed one of my errors, which now only leaves me with my attempt to index nil on line 8 of my server script

No one has canceled this fix and it is still relevant.

I meant this line specifically, that line has been fixed, sorry if you got confused-

I found out why its erroring out, I made a check for if the player exists, and if the player doesnt exist, the script will return end. Player doesnt exist somehow, so it might just be cause im in studio or some other reason in the code

Edit: Its the code that has a problem

1 Like

Right now, your server is receiving:
Player:Player, Username:Player, KillCount:string, [blank variable]:number
Remove the first argument on the client and with one mod, server code should work.

Replace this line with game.Players:FindFirstChild(Username)

When using remote events, you do NOT have to send the player over from the client, the only time you should have a Player as an argument is when using FireClient.

Here is the issue:

local Name = Button.Parent.Name

Your text box’s name is “Name”
However the button’s parent also has a property called “Name”
This way a conflict begins and the instance Name is the name of the button’s parent, not the text box with name “Name”
Change the textbox’s name to something like “PlayerName” and issue is fixed.
Yeah, its weird, I encounter it all the time.

1 Like

That was the solution, thanks for the others for pointing out the other errors I made too

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.