Attempt to get length of nil value invokeserver thing

local script:

local plr = game.Players.LocalPlayer 
local textplace = script.Parent.Parent.resulttext
local Market = game:GetService("MarketplaceService")
local function typeText(text)
	for i = 1, #text do
		textplace.Text = string.sub(text, 1, i)
		wait()
	end
	wait(7)
	textplace.Text = ""
end
script.Parent.MouseButton1Down:Connect(function()
	
	local user = script.Parent.Parent.Username.Text
	
	if  game.Players:FindFirstChild(user) then
			local result = game.ReplicatedStorage Events.Request:InvokeServer(game.Players:FindFirstChild(user))
		
		
		typeText(result)
	else
		script.Parent.Text = INVALID PLAYER."
		wait(3)
		script.Parent.Text = "Kick player"
	end
end)

Server Script:

local Can = false
function KickRequest(Player,PlayerToKick)
if Player and PlayerToKick then
local function kick(player)
player:Kick("You have been kicked")
return "Success"
end
local function detect()
if Player.Name ~= "uugnut6" then
KickRequest()
else
Can = true
return
end

detect() 
repeat wait() until Can == true
kick(PlayerToKick)
end
end

Event.OnServerInvoke = KickRequest

At what line are you getting this error?

Also, the end of your code is malformed.

else
		script.Parent.Text = INVALID PLAYER."
		wait(3)
		script.Parent.Text = "Kick player"
	end
end)

should be

else
		script.Parent.Text = "INVALID PLAYER."
		wait(3)
		script.Parent.Text = "Kick player"
	end
end)

im getting it at textplace.Text = string.sub(text, 1, i) because text is nil

this means that the value my remote function returned is nil

I think you mean to do game.ReplicatedStorage.Events? You have a random space between ReplicatedStorage and Events, if you want to print it with the space, do tostring()

that fixed a issue but its still returning nil

Everything in the code works, the player gets kicked, the only thing that breaks is that the function is returning “nil”

Doesn’t this just subtract 1 in (text) and then subtract 1 with i again?

that function is for animated text

Would doing: textplace.Text = string.sub(text, i, i + 1) fix it? :thinking:

i dont think the error is related to the animated text, when i did print(result) it printed nil

1 Like

I don’t think you have to do game.Players:FindFirstChild(user) again in the local result =, as you already made the script check if game.Players:FindFirstChild(user) then. so, maybe you just have to do game.Players.user? Just maybe.. not too sure..

Could you please send a screenshot of the error you’re getting in the console?

when i do that it thinks “user” is a player in game

There’s no error, it’s just result is returning as nil, which means it’s getting nothing, that’s the issue for him.

Not every script fails comes with an error

Have you stated what “Event” is in the script?

yes event i stated i just probably forgot to put it in that msg

Try doing:

if game.Players:FindFirstChild(user) then
            local player = game.Players:FindFirstChild(user) 
			local result = game.ReplicatedStorage.Events.Request:InvokeServer(player)

The issue could be stemming from the fact that in the serverscript you create a function that returns nil and then you call that function.

local function detect()
if Player.Name ~= "uugnut6" then
KickRequest()
else
Can = true
return
end

detect() 

In the “detect” function instead of just returning instead try to return a string value and check if “text” in the localscript is still nil.

1 Like