My notification system is having issues with the error "attempt to call instance value"

KillerFrog11

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.

Piglet

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

System.FormatException error and having issues trying to fix it

I'm having issues with the boolean in my if statements

Having issues getting a newline on my code

Having issues passing counts in my scheduler function

Having issues on my drop-down menu

Having issues with charset in my blazor project

Having issues with my long running task

Having issues with my onClick on a registration form

Having Issues Locating my Data Partiton in WINE

im having some issues with my php code

Having issues trying to make my dataframe numeric

Having issues with SGD/Keras in my AI chatbot

Having same output when running my system

Having issues using axios to handle my JSON data

I'm having issues getting AngularJS to display my table correctly

Having issues typing into my input box or clicking on things[React]

Having issues with my TFS 2013 Installation after the previous installation expires

having issues setting up and displaying the sprites in my classes/subclasses in pygame

I am having issues getting a return from my function

Having issues setting up the view model for my webpage

reactjs - having some issues with my functions to update state and using promises

I am having issues with displaying my custom objects in a ListView android

My wampserver seems to be having issues dealing with external JS and CSS files

Why am I having issues with my flutter firebase authentification?

my diceroller is having issues with removing elements from the list, any suggestions?

Having issues of having Bootstrap NAV TABS and Grid System working in the same page

Having issues resolving compiler error C2678

Trying to generate a Shiny Web App but having issues with arg error

Having some error issues about designing a blog in Ruby on Rails