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

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

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

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)

6 comments

0

Oh! I see now. Thanks for the help! This site is really proving of its support. It works! ;D

0

You're welcome! Oh, don't forget to accept the answer.

0

How?

0

Doesn’t have to accept

0

But, he solve it so i acept.

0

O. Someone told me, that you need more than 0 rep to accept answer. But, thanks for trying

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