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

Roblox attempt to call a userdata value errror in my code. why?

So, I followed a tutorial on how to make a Roblox map voting system but I keep getting this error "attempt to call a userdata value" this happens on these two lines of code:

		table.insert(vars.services, game("GetService","RunService").RenderStepped:connect(function()

and

game("GetService","RunService").RenderStepped:connect(function()

If anybody knows how to fix this I would greatly appreciate it! it's the only error I am currently getting. Thanks :)

Whole script:

--player--
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local gui = player:WaitForChild("PlayerGui")
local ui = gui:WaitForChild("ui")

--Assets--
local rep = game.ReplicatedStorage
local assets = rep.Assets

--Maps--
local maps = assets.Maps

--Signals--
local signals = assets.Signals
local event = signals.Event
local fevent = signals.FEvent

--Game Variables--
local Game = workspace.Game
local stats = Game.Stats

--Static Variables--
local vars = {
	currentVote=nil;
	services={};
}

--Primary Events--
event.OnClientEvent:connect(function(variables)
	if variables.reason == "startVoting" then
		table.insert(vars.services, game("GetService","RunService").RenderStepped:connect(function()
			local ray = Ray.new(char.PrimaryPart.CFrame.p, Vector3.new(0,-1000,0))
			local object = workspace:FindPartOnRay(ray, char, false, false)
			if object and object.Name:match("VotingPad") then
				local votingPadNum = tonumber(object.Name:match("%d+"))
				if vars.currentVote== nil then
					vars.currentVote = votingPadNum
					event:FireServer({reason="voteOnMap"; itemNum=votingPadNum;})
				elseif vars.currentVote~=votingPadNum then
					vars.currentVote = votingPadNum
					event:FireServer({reason="voteOnMap"; itemNum=votingPadNum;})
				end
			elseif vars.currentVote~=nil then
				vars.currentVote=nil
				event:FireServer({reason="removeFromVote"})
			end
		end))
		elseif variables.reason == "endVoting" then
			for a,b in pairs(vars.services) do
				b:disconnect()
			end
			vars.services={}
	end
end)

--initiate Title Updater
game("GetService","RunService").RenderStepped:connect(function()
	ui:WaitForChild("Title").Text = stats.Status.Value
end)

1 comment

0

Your script is outdated.

1 answer

You can add services into a table, but its really dumb, considering you can add this to the top of your script

local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function()
	-- ...
end)

2 comments

0

Sadly this didnt work, ill send the whole script

0

I edited it to see the whole script

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