Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the local Script printing nil for a string that's passed via Script? [ Answered]

FilteringEnabled is on and I'm using RemoteFunctions for this. The argument MapString is a string taken apart from what someone chatted, however when I print it in the Local Script that is waiting to get called on, it's nil for some reason, why is this so?

  • Server Script
local ClientFunction = Instance.new("RemoteFunction", game.Workspace)
ClientFunction.Name = "ClientFunction"

game.Players.PlayerAdded:connect(function(Plr)
		Plr.Chatted:connect(function(Msg)
			if string.sub(string.lower(Msg), 0, 9) == "computer " then
				if string.sub(string.lower(Msg), 10, 14) == "load " then
					if game.ReplicatedStorage:FindFirstChild(string.sub(string.lower(Msg), 15)) then
						local MapString = string.sub(string.lower(Msg), 15)
						ClientFunction:InvokeClient(Plr, MapString)
					end
				end
			end
		end)
end)
  • Local Script (Client)

local ClientFunction = game.Workspace:WaitForChild("ClientFunction")

function ClientFunction:OnClientInvoke(MapName)
	print(MapName)

end

  • Answer bellow

Thanks to M39a9am3R's help, he pointed out that I used a : instead of a . for function ClientFunction:OnClientInvoke(MapName)

1 answer

✓ Accepted answer

On line 3 of the local script, you are substituting a colon for a period. Colons are used for methods, and since the ClientFunction is not a table or an object with that accepts OnClientInvoke as a valid method, a period must be used, similar to an event. (part.Touched;game.Players.PlayerAdded)

Local Script

local ClientFunction = game.Workspace:WaitForChild("ClientFunction")

function ClientFunction.OnClientInvoke(MapName)
    print(MapName)
end

1 comment

0

Already said it was answered m8

This discussion is preserved as it was. New answers, comments, and votes are closed.