This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: Attempt to call method 'GetTarget' (a nil value)  (Read 887 times)

Kobiesan

  • Registred Member
  • Wiki Incarnate
  • *****
  • Posts: 161
    • View Profile
Attempt to call method 'GetTarget' (a nil value)
« on: May 23, 2017, 07:32:28 am »
I have this dummy script for a spell that strangles the target. I've attempted to do this by using this dummy script (eluna):

Code: [Select]
local function onCast(effectIndex, spell)
local target = spell:GetTarget()
if (spell:GetTarget():IsPlayer() == true) then
while player:IsCasting(81076) do
target:EmoteState(474)
end
end
end

RegisterPlayerEvent(PLAYER_EVENT_ON_SPELL_CAST, onCast)

However, when it's cast I get a "Attempt to call method 'GetTarget' (a nil value)" does anyone know what this error means?

Kaev

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 308
    • View Profile
Re: Attempt to call method 'GetTarget' (a nil value)
« Reply #1 on: May 23, 2017, 09:40:47 am »
Your argument spell is nil/null. Error says you can't get the target from something that doesn't exist. Make sure spell is not nil/null, e.g. by adding if (spell) then {code} end

Kobiesan

  • Registred Member
  • Wiki Incarnate
  • *****
  • Posts: 161
    • View Profile
Re: Attempt to call method 'GetTarget' (a nil value)
« Reply #2 on: May 23, 2017, 08:00:08 pm »
Your argument spell is nil/null. Error says you can't get the target from something that doesn't exist. Make sure spell is not nil/null, e.g. by adding if (spell) then {code} end

Can you elaborate a bit more?