it keep erroring "attempt to call a string value"
01 | local rep = game:GetService( "ReplicatedStorage" ) |
02 | local userinput = game:GetService( "UserInputService" ) |
03 |
04 | local Print = function (p) |
05 | print ( "Lazy" ) |
06 | end |
07 |
08 | remotes = { |
09 | Print = rep:WaitForChild( "RemoteEvent" ) |
10 | } |
11 |
12 |
13 | game.Players.PlayerAdded:Connect( function (p) |
14 | p.CharacterAdded:Connect( function (c) |
15 | for name, event in pairs (remotes) do |
16 | event.OnServerEvent:Connect(name) |
17 | end |
18 | end ) |
19 | end ) |
You're calling the variable/name "Print" instead of indexing the function and calling that in your onserverevent. Try this. It should work. Though. I don't recommend doing this using tables. It'll slow down the script. Since the in pairs loop, loops through the table, it takes time. There is a solution for that though.
01 | local rep = game:GetService( "ReplicatedStorage" ) |
02 | local userinput = game:GetService( "UserInputService" ) |
03 |
04 | local Print = function (p) |
05 | print ( "Lazy" ) |
06 | end |
07 |
08 | remotes = { |
09 | [ Print ] = rep:WaitForChild( "RemoteEvent" ) |
10 | } |
11 |
12 |
13 | game.Players.PlayerAdded:Connect( function (p) |
14 | p.CharacterAdded:Connect( function (c) |
15 | for name, event in pairs (remotes) do |
16 | event.OnServerEvent:Connect(name) |
17 | end |
18 | end ) |
19 | end ) |