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

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

Asked by 5 years ago
Edited 5 years ago

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)
0
OnServerInvoke is a callback function of RemoteFunction, use OnServerEvent User#23365 30 — 5y
0
OnClientInvoke and OnServerInvoke are for remote functions User#23365 30 — 5y
0
What should i change Invoke from LocalScript to? ady1111 8 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

Ad

Answer this question