Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

OnServerInvoke is not a valid member of RemoteEvent.How to fix?

Tried using:

game.ReplicatedStorage.tryToPurchase.OnServerInvoke:connect ( function (player, cost , spaces)

or

game.ReplicatedStorage.tryToPurchase.OnServerInvoke = function(player, cost, spaces)

but i get the same error.

LocalScript: (GUI)

local buyButton = script.Parent
local newSpaces = 1000000
local upgradeCost = 100000000

local function giveUpgrade()
    game.ReplicatedStorage.tryToPurchase:Invoke(upgradeCost, newSpaces)
end

script.Parent.Activated:Connect(giveUpgrade)

Script: (ServerScriptStorage)

game.ReplicatedStorage.tryToPurchase.OnServerInvoke:connect(function(player, cost, spaces)

    local playerStats = player:FindFirstChild("leaderstats")
    local playerGold = playerStats:FindFirstChild("Gold")
    local playerSpaces = playerStats:FindFirstChild("Spaces")

    if playerGold.Value >= upgradeCost then
        playerGold.Value = playerGold.Value - cost
        playerSpaces.Value = spaces
    end
end)

3 comments

0

OnServerInvoke is a callback function of RemoteFunction, use OnServerEvent

0

OnClientInvoke and OnServerInvoke are for remote functions

0

What should i change Invoke from LocalScript to?

1 answer

✓ Accepted answer

Well that's a simple answer; OnServerInvoke is not a callback of Remote Event. Instead, it is a callback of a Remote Function. The solution would be to use a Remote Function instead of a Remote Event.

This discussion is preserved as it was. New answers, comments, and votes are closed.