I want to remove the unknown global error for self. (self.properties.owner}
What is the issue?
While the script still works I believe it is causing issues elsewhere.
What solutions have you tried so far?
I’ve searched through the dev forums and I’ve also checked elsewhere. While I’ve learned new stuff, I was not able to fix my current issue.
My main issue is I’m noob and I’m sure this is something really silly I’m missing. Any type of guidance would be appreciated.
function script.canSpawnAnimal.OnInvoke(player, animalType)
local totalCount = getPlayerAnimals(player)
local playerLevel = game.ServerScriptService.stats.getStat:Invoke(player, "farmLevel")
local cost, animalLimit, plantLimit = require(game.ReplicatedStorage.libraries.farm).getLevelInformation(playerLevel)
if totalCount >= animalLimit then
game.ReplicatedStorage.remotes.player.flashUpgrade:FireClient(self.properties.owner)
return false, "Your animal limit is: "..animalLimit.."!"
else
return true
end
You have to have a class (metatable) to use self in any way, but because you are trying to access it in a script, create the metatable with the variable, and access the data using the variable.
self isn’t defined in this context. self is only automatically defined if the function itself is defined with a colon (i.e. function script.canSpawnAnimal:OnInvoke).
However, judging by your script, you seem to be using a BindableFunction, in which case, this wouldn’t work
function script.canSpawnAnimal.OnInvoke(player, animalType, self)
local totalCount = getPlayerAnimals(player)
local playerLevel = game.ServerScriptService.stats.getStat:Invoke(player, "farmLevel")
local cost, animalLimit, plantLimit = require(game.ReplicatedStorage.libraries.farm).getLevelInformation(playerLevel)
if totalCount >= animalLimit then
game.ReplicatedStorage.remotes.player.flashUpgrade:FireClient(self.properties.owner)
return false, "Your animal limit is: "..animalLimit.."!"
else
return true
end
function script.canSpawnAnimal.OnInvoke(player, animalType)
local totalCount = getPlayerAnimals(player)
local playerLevel = game.ServerScriptService.stats.getStat:Invoke(player, "farmLevel")
local cost, animalLimit, plantLimit = require(game.ReplicatedStorage.libraries.farm).getLevelInformation(playerLevel)
if totalCount >= animalLimit then
game.ReplicatedStorage.remotes.player.flashUpgrade:FireClient(player) -- Here, use 'player' instead of 'self.properties.owner'
return false, "Your animal limit is: "..animalLimit.."!"
else
return true
end
end