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)
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)
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
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.