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)
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.