Forum > Serverside Modding

Attempt to call method 'GetTarget' (a nil value)

(1/1)

Kobiesan:
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: ---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)
--- End code ---

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

Kaev:
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:

--- Quote from: Kaev 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

--- End quote ---

Can you elaborate a bit more?

Navigation

[0] Message Index

Go to full version