Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to fix this error? attempt to call a string value?

Asked by 6 years ago

it keep erroring "attempt to call a string value"

01local rep = game:GetService("ReplicatedStorage")
02local userinput = game:GetService("UserInputService")
03 
04local Print = function(p)
05    print("Lazy")
06end
07 
08remotes = {
09    Print = rep:WaitForChild("RemoteEvent")
10}
11 
12 
13game.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)
19end)

1 answer

Log in to vote
1
Answered by
Delude_d 112
6 years ago

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.

01local rep = game:GetService("ReplicatedStorage")
02local userinput = game:GetService("UserInputService")
03 
04local Print = function(p)
05    print("Lazy")
06end
07 
08remotes = {
09    [Print] = rep:WaitForChild("RemoteEvent")
10}
11 
12 
13game.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)
19end)
0
Oh! I see now. Thanks for the help! This site is really proving of its support. It works! ;D Coolest_F0rces 0 — 6y
0
You're welcome! Oh, don't forget to accept the answer. Delude_d 112 — 6y
0
How? Coolest_F0rces 0 — 6y
0
Doesn’t have to accept User#19524 175 — 6y
View all comments (2 more)
0
But, he solve it so i acept. Coolest_F0rces 0 — 6y
0
O. Someone told me, that you need more than 0 rep to accept answer. But, thanks for trying Delude_d 112 — 6y
Ad

Answer this question