Why doesn't this script fire the function from the ModuleScript table?

I am doing a script that woud allow me to call many functions using only one RemoteEvent. For this I am using a module script to store all my functions in a table and call them when I need with the appropriate arguments that I pass from the ServerScript. However, the code stops working in the ServerScript for some reason, just when the code is about to fire the function from the ModuleScript. Any ideas would be welcomed! I can provide more details if it is needed.

LocalScript: Firing the server when a button is pressed

Button.MouseButton1Up:Connect(function()
	local Position = "1Spawn"
	RemoteEvent:FireServer("Teleport1Spawn", Position)
end)

ServerScript: Receiving the FireServer and calling a certain function in the ModuleScript table depending on the “Argument”. Here is where the code stops working.


local module = require(ReplicatedStorage.ModuleScript)

RemoteEvent.OnServerEvent:Connect(function(Player, Argument, Position)
	if module.Functions and module.Functions[Argument] then
		module.Functions[Argument](Position) -- CODE STOPS WORKING
	end
end)

ModuleScript: Calls a certain function from the table based on the “Argument” (For now I have only one function “Teleport1Spawn” in the table)

local module = {}

local Players = game.Players

function module.Teleporter(Position)
for i, v in pairs(Players:GetChildren()) do
	v.Character.HumanoidRootPart.CFrame = Position.CFrame
	end
end

module.Functions = {
	["Teleport1Spawn"] = function(Position)
		module.Teleporter(Position)
	end
}

return module

code seems fine except for Position being a string while trying to access Position.CFrame, perhaps you should look for something wrong besides the code

2 Likes

Seems like this is the error, something along the lines of no index “CFrame” in string. Are there any errors listed in your output log?

1 Like

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