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"

local rep = game:GetService("ReplicatedStorage")
local userinput = game:GetService("UserInputService")

local Print = function(p)
    print("Lazy")
end

remotes = {
    Print = rep:WaitForChild("RemoteEvent")
}


game.Players.PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(c)
        for name, event in pairs (remotes) do
            event.OnServerEvent:Connect(name)
        end
    end)
end)

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.

local rep = game:GetService("ReplicatedStorage")
local userinput = game:GetService("UserInputService")

local Print = function(p)
    print("Lazy")
end

remotes = {
    [Print] = rep:WaitForChild("RemoteEvent")
}


game.Players.PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(c)
        for name, event in pairs (remotes) do
            event.OnServerEvent:Connect(name)
        end
    end)
end)
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