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

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

Asked by 4 years ago
Edited 4 years ago

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)
0
Your script is outdated. youtubemasterWOW 2741 — 4y

1 answer

Log in to vote
1
Answered by
iuclds 720 Moderation Voter
4 years ago

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)
0
Sadly this didnt work, ill send the whole script pokemine1o9 44 — 4y
0
I edited it to see the whole script pokemine1o9 44 — 4y
Ad

Answer this question