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 6 years ago
Edited 6 years ago

Tried using:

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

or

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

but i get the same error.

LocalScript: (GUI)

1local buyButton = script.Parent
2local newSpaces = 1000000
3local upgradeCost = 100000000
4 
5local function giveUpgrade()
6    game.ReplicatedStorage.tryToPurchase:Invoke(upgradeCost, newSpaces)
7end
8 
9script.Parent.Activated:Connect(giveUpgrade)

Script: (ServerScriptStorage)

01game.ReplicatedStorage.tryToPurchase.OnServerInvoke:connect(function(player, cost, spaces)
02 
03    local playerStats = player:FindFirstChild("leaderstats")
04    local playerGold = playerStats:FindFirstChild("Gold")
05    local playerSpaces = playerStats:FindFirstChild("Spaces")
06 
07    if playerGold.Value >= upgradeCost then
08        playerGold.Value = playerGold.Value - cost
09        playerSpaces.Value = spaces
10    end
11end)
0
OnServerInvoke is a callback function of RemoteFunction, use OnServerEvent User#23365 30 — 6y
0
OnClientInvoke and OnServerInvoke are for remote functions User#23365 30 — 6y
0
What should i change Invoke from LocalScript to? ady1111 8 — 6y

1 answer

Log in to vote
0
Answered by 6 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