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

Map voting script not working, how can I fix it? Is it fixable?

Asked by 4 years ago

Im working on a map voting system I followed from a tutorial, the scrip looks like this


--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)

Im getting an error "attempt to call a user value" on line 58 and 32. How can I fix it, if it's fixable.

1 answer

Log in to vote
0
Answered by 4 years ago

Hello. The problem is that you used GetService() wrong. Instead of game("GetService, "RunService"), you have to use game:GetService("RunService"). Please try doing more research before asking. Try this:

--player--
local player = game:GetService("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)

Please accept and upvote this answer if it helps.

0
Appriciate it so much. I apologies, next time ill do mybest and ask as a last resort. Once again thank you so much. pokemine1o9 44 — 4y
0
That's fine, you don't need it as a last resort, but before posting just try searching on google. Anyway, no problem. youtubemasterWOW 2741 — 4y
Ad

Answer this question