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
OnServerInvoke is a callback function of RemoteFunction, use OnServerEvent
OnClientInvoke and OnServerInvoke are for remote functions
What should i change Invoke from LocalScript to?