:FireClient() argument not going through correctly

Title says it all. The arguments are not going through correctly. I’ve tried searching on DevForum and ScriptingHelpers to find answers but it seems like no one has the same problem as me. Please help, I’ve been struggling for almost 5 days now. In short, KeyVar is apparently empty/blank/nil upon printing on the LocalScript/Client.

ServerScript:

RunService.Heartbeat:connect(function()
	local Text = ""
	for i = 1,30 do
		Text = Text..string.char(math.random(97,122))
	end
	for i,Constraints in pairs(Instances) do
		Constraints.Name = Text
	end
	StringValue.Value = Text
	print(StringValue.Value .. " | Server")
	print(Text .. " | Server")
	TitanKey:FireClient(Player, Text)
end)

LocalScript:

local KeyVar = ""

TitanKey.OnClientEvent:Connect(function(Key)
	KeyVar = Key
end)

spawn(function()
	while wait() do
		print(KeyVar .. " | KeyVar")
	end
end)

What it prints on both ServerScript and LocalScript: (Ignore, jaohstpfefukjvfebimnwbboxaiols | Name. That’s not relevant)
Imgur

Note: I’ve also tried, (and it does not work)

RunService.Heartbeat:connect(function()
	local Text = ""
	for i = 1,30 do
		Text = Text..string.char(math.random(97,122))
	end
	for i,Constraints in pairs(Instances) do
		Constraints.Name = Text
	end
	StringValue.Value = Text
	print(StringValue.Value .. " | Server")
	print(Text .. " | Server")
	TitanKey:FireClient(Player, StringValue.Value)
end)

Alrighty, does this occur the first time you fire the event?

No. It does not occur the first time I fire the event.

Have you tried printing Key ? And if you have what result did you get?

It prints the Key (It’s not empty or nil).

honestly, if you are firing the remote event on heartbeat, there is actually no point in doing this:

You could simply use Key for whatever you have to inside the OnClientEvent Connection

True, but my script wont work if I do that.

The error is here. You don’t need to use quotes here you can just do

local KeyVar

TitanKey.OnClientEvent:Connect(function(Key)
    KeyVar = Key
end)

The key is not going through the between two quotes so you wouldn’t use it. So you define the variable in OnClientEvent event.

I’ll try that out real quick and I’ll tell you if there’s anything wrong.

This is the error I got,
Imgur

This won’t work, you are setting KeyVar to nil, and then while loop is attempting to concatenate nil with a string in the while loop, essentially causing the script to error

If you don’t mind me asking, what exactly are you trying to do with KeyVar?

Basically some whitelist system in the Character, it is a very complicated system and I probably don’t have the skill or knowledge to put it in words.

I will try that out real quick.

It is the same error like last time.

What is the purpose of running the while loop though?

Keep’s it updating so no exploiters can mess with it or change their created instances name to that.

Oh okay, then you don’t really need the while loop, since you are running on Heartbeat,

TitanKey.OnClientEvent:Connect(function(key)

end)

is the equivalent of

local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function()

end

and also if I am not mistaken, RunService.Heartbeat is actually faster than while wait() do.

I don’t know what you want me to do here or have an idea of what you are trying to tell me and yes it is indeed faster.

Edit: It is 4 AM for me right now so my mind is a bit slow.

So the spawn thread is actually running behind the OnClientEvent thread, essentially causing a ‘delay’. The reason KeyVar is not printing anything is that the spawn thread is running OnClientEvent.