OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available

Update - figured it out

So I’m making a real estate system, and in another script not shown below the ProfitAmount.Value is put in a loop that determines how much the real estate property earns in profit every 5 seconds.

My problem occurs when I added a UI button in the owner pannel that allows players to increase the ProfitAmount.Value so they make $45 per 5 seconds rather than $35. When I press the button, nothing happens and the profit stays at $35.

Usually when I have an error, I can figure out the issue without needing to post here. But this is the 2nd time I’ve rewritten the code, and I was pretty confident in this attempt and then ended up getting the same exact error. Does anyone have any idea what this error means?

 OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available
8 Likes

Server invoke is a callback; so you have to define it in your code just a bit differently versus connecting it like other normal events.

If I’m not mistaken, this should work:

profitUpgradeFunction.OnServerInvoke = function(player)
    if game.ServerStorage.PlayerMoney[player.Name].Value > upgradeCost then
        if ProfitAmount.Value == profitIncrease then
            game.ServerStorage.PlayerMoney[player.Name].Value = game.ServerStorage.PlayerMoney[player.Name].Value - upgradeCost
            ProfitAmount.Value = profitIncrease2
        elseif ProfitAmount.Value == profitIncrease2 then
            game.ServerStorage.PlayerMoney[player.Name].Value = game.ServerStorage.PlayerMoney[player.Name].Value - upgradeCost
            ProfitAmount.Value = profitIncrease3
        end
        return true
    elseif game.ServerStorage.PlayerMoney[player.Name].Value < upgradeCost then
        return false
    end
end
40 Likes

Yep! I had to do that and remove this line from the local script:

ProfitAmount.Changed.Connect(function()

Works perfectly now!

3 Likes

Glad to hear! :grin:

30characters

4 Likes