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

[SOLVED] attempt to index local 'variable' (a number value)?????

Asked by 4 years ago
Edited 4 years ago

[SOLVED] ok?

Hi!

I'm making a game where you have to write your answer (string) to a random question and then people have to vote which answer is the best.

When a player submits their answer, a LocalScript will fire a remote event to a basescript which will create a StringValue and named it the "answer-creator" (player.UserId converted into string) and the value is the answer string and parented to a folder named playerssubmissions inside ReplicatedStorage. Then it creates a NumberValue named votes and parented into the StringValue.

After that, the basescript will fire a remove event to all clients and the localscript will do this weird stuff... I'll try my best explaining this...

So first, It'll create a BoolValue named voted and parented it in all players. This is used to see if the player has voted or not. Secondly, it will start the for i, variable in pairs(table) thing. Here's the code if you need it:

for _, answers in pairs(submissions) do
            local gigi = rep.Others:WaitForChild("answersample"):Clone()
            gigi.creator.Value 
 = game.Players:GetPlayerByUserId(tonumber(answers.Name))
            gigi.sub.Value = answers
            local filteredtext = re2:InvokeServer(answers.Value,answers.Name)
            gigi.Text = "\""..filteredtext.."\""
            gigi.Parent = player.PlayerGui.VotingGui.Frame

The submissions table thingy is the playersubmissions in the ReplicatedStorage by the way.

It'll clone the TextButton named answersample located in Others folder inside ReplicatedStorage (rep).

(The TextButton contains 2 ObjectValues. One is creator which is the 'creator of the answer' and another one is sub which is the StringValue located in the playerssubmissions.)

Then it will get some stuff and text and stuff and finally parenting the textbutton inside the VotingGui.Frame

Now when it comes to voting, players will click one of the answers to vote and when they click one, a localscript will call an event which is:

script.Parent.MouseButton1Click:Connect(function()
local creator = game.Players:FindFirstChild(tostring(script.Parent.creator.Value))
    local userid = creator.UserId
    local sub = rep.playerssubmissions:FindFirstChild(tostring(userid))
    if voted.Value == false then
        voted.Value = true
        re:FireServer(sub)
end
end

First, it'll get the player's userid and the answer and then fire the server with an argument which will trigger a function in a script that will add the vote:

local rep = game:GetService("ReplicatedStorage")
local re = rep.reServer:WaitForChild("votesub")

re.OnServerEvent:Connect(function(sub)
    sub.votes.Value = sub.votes.Value + 1
end)

And when it's running sub.votes.Value = sub.votes.Value + 1, it throws an error which is attempt to index localsub(a number value) which I don't understand because sub is a StringValue and not NumberValue. I tried doing print(sub.Value) to find what's wrong but it just threw the same thing.

This is such a stupid thing to do but whatever because I don't know how to fix it.

Any help is appreciated!

0
OnServerEvent(player, sub). Player parameter is first before other parameters. Try adding it and then tell me what happens YTRaulByte 389 — 4y
0
oh #$% i totally forgot about that first parameter ugh... unpurrity 4 — 4y
0
If YTRaulByte's suggestion fixed your script, edit your title and put [Solved] in the very beginning. And why not upvote their comment since it was technically an answer? :) SteelMettle1 394 — 4y
0
Yeah sure but I don't have enough reputation to upvote! unpurrity 4 — 4y

Answer this question