Jump to content

[HELP]getElementData error


Recommended Posts

Hello, my script is giving out the error "Expected element, got nil" but I tried everything and cannot manage to fix it

function findPlayer( namepart ) 
    local player = getPlayerFromName( namepart ) 
    if player then 
        return player 
    end 
    for _,player in pairs( getElementsByType 'player' ) do 
        if string.find( string.gsub( getPlayerName( player ):lower( ),"#%x%x%x%x%x%x", "" ), namepart:lower( ), 1, true ) then 
            return player 
        end 
    end 
    return false 
end 

 addCommandHandler( 'heal', function( source,_,player ) 
    local find = findPlayer( player ) 
    if find then	    
    	    setElementData(find, "healStatus", true)
      		outputChatBox("The doctor is willing to heal you. Do you accept?", find)
    else
      outputChatBox("Player not found!", source, 255, 0, 0)
	end
end)

function acceptHeal()
  local requestStatus = getElementData(player, "healStatus")
  if requestStatus == true then
  	setElementData(player, "healStatus" , false) -- delete it!
    setElementHealth(player, 100)
    outputChatBox("You have been healed by the doctor.", player)
  else
    outputChatBox("You have no pending request.", player)
  end
end
addCommandHandler("aheal", acceptHeal)

 

Edited by Galactix
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...