0

So the full code is here in the two parts: Server and Local. I am trying to make a system that stores the Balance of the user, from the table, in a IntValue inside of their player in game.Players then call it later to check if it has changed. If It has, send a Notification to the GUI via a local script. Whatever happens, the notification does not appear. If you need anything else, I'm happy to give you it. Thanks for reading and any potential help. This is for a game called Opix Islands on Roblox, I am not an expert nor a noob, I just got a bit stuck.

Server:

    while true do
    for i,v in game.Players do --this is the line with the error.

            local tab = nil
            for I,V in pairs(_G.GlobalData) do
                if V.UserId == v.UserId then
                    tab = V
                end
            end
            if not v.Bank then
                newval = Instance.new("IntValue",v)
                newval.Name = "Bank"
                wait()
                newval.Value = tab.Bank

            else
                if tab.Bank > v.Bank.Value then
                    print ("Greater than stored value")
                    local changedby = tab.Bank - v.Bank.Value
                    game.ReplicatedStorage.Notif.Return:FireClient(v,changedby,false)
                elseif tab.Bank < v.Bank.Value then
                    print ("Less than stored value")
                    local changedby = v.Bank.Value - tab.Bank
                    game.ReplicatedStorage.Notif.Return:FireClient(v,changedby,true)--Player to send to,amount it has changed by,If it has gone down
                end             
            end
            
        end

    wait()  
    end
    

And the Local script:

game.ReplicatedStorage.Notif.Return.OnClientEvent:Connect(function(Change,Down)
     if Down == false then
        local Notification = script.Parent.NotificationExample:Clone()
        Notification.Name = "Notification"
        Notification.Parent = script.Parent
        Notification.Text = "Your Bank account balance has just increased by: £"..Change
        print ("Bank account Increased by:"..Change)
        Notification.Visible = true
        print ("Notification should be visible")
        wait(3)
        Notification:Destroy()
        print ("Notification should be gone!")
    elseif Down == true then
            local Notification = script.Parent.NotificationExample:Clone()
            Notification.Parent = script.Parent
            Notification.Name = "Notification"
            Notification.Text = "Your Bank account balance has just decreased by: £"..Change
            print ("Bank account decreased by:"..Change)
            Notification.Visible = true
            print ("Notification should be visible")
            wait(3)
            Notification:Destroy()
            print ("Notification should be gone!")
    
    
    
    end
    
    
end)

Here's a picture of the hierarchy, the event is in the replicated storage. hierarchy

Many Thanks.

  • well looks like you're calling an instance value somewhere. I cannot see such a call in the provided code. so maybe it happens because you provided an instance instead of a function value as a callback or so. please do your own debugging. error messages usually come with a line number btw – Piglet Jan 02 '21 at 10:03
  • Its the marked line. Line 18. for i,v in game.Players do – KillerFrog11 Jan 02 '21 at 10:04

2 Answers2

1

Looks like game.Players is not a function.

Something like this

for i,v game.Players do

end

cannot work.

From the Lua manual:

A for statement like

 for var_1, ···, var_n in explist do body end works as follows.

The names var_i declare loop variables local to the loop body. The first of these variables is the control variable. The loop starts by evaluating explist to produce four values: an iterator function, a state, an initial value for the control variable, and a closing value.

Then, at each iteration, Lua calls the iterator function with two arguments: the state and the control variable.

In your case Lua will treat game.Players as the iterator function as this is the first (and only) element of the explist you provide. When called it will result in the observed error as it is not a function value.

You probably want to do something like

for i,v in ipairs(game.Player:GetChildren()) do end
Piglet
  • 27,501
  • 3
  • 20
  • 43
-1
    while true do
    for i,v in pairs(game.Players:GetChildren()) do --this is the line with the error.

            local tab = nil
            for I,V in pairs(_G.GlobalData) do
                if V.UserId == v.UserId then
                    tab = V
                end
            end
            if not v.Bank then
                newval = Instance.new("IntValue",v)
                newval.Name = "Bank"
                wait()
                newval.Value = tab.Bank

            else
                if tab.Bank > v.Bank.Value then
                    print ("Greater than stored value")
                    local changedby = tab.Bank - v.Bank.Value
                    game.ReplicatedStorage.Notif.Return:FireClient(v,changedby,false)
                elseif tab.Bank < v.Bank.Value then
                    print ("Less than stored value")
                    local changedby = v.Bank.Value - tab.Bank
                    game.ReplicatedStorage.Notif.Return:FireClient(v,changedby,true)--Player to send to,amount it has changed by,If it has gone down
                end             
            end
            
        end

    wait()  
    end
CozLex
  • 51
  • 4