Jump to content

attempt to index global 'Player' (a nil value)


Zuher Laith

Recommended Posts

Hello everyone,

I'm working on a resource that sends a dx message to the player on both server/client side and gets called from other resources .

this is the full code:

  Reveal hidden contents


So in case I want to call and pass a message on server side from another resource, I use this:

  Quote

triggerClientEvent(thePlayer, "dxMessage.dxOutputMessage", thePlayer, "Message passed ! !", 0, 255, 0)

Expand  


and If I wanted to pass it on client side, I use "call" function:

  Quote

call(getResourceFromName("[add]DxMessage"), "outputMessage", "Message passed !", 0, 255, 0)

Expand  


this is the first error I got after debugging:

  Quote

ERROR: [add]DxMessage\server.lua:9: attempt to index global 'Player' (a nil value)

Expand  


I know its a bit messy,
Any help is appreciated .

Edited by Zuher Laith
Link to comment
  • Moderators
function dxOutputMessage(message, player, r, g, b) -- this works for server side trigger from another resource
	triggerClientEvent(player, "dxMessage.dxOutputMessage", player, message, r, g, b);
end

function outputMessage(message, player, r, g, b)
	dxOutputMessage(message, player, r, g, b);
end

addEvent("dxMessage.outputMessage", true);
addEventHandler("dxMessage.outputMessage", root, function(message, r, g, b)
	outputMessage(message, client, r, g, b); -- and here
end);

 

 

It is not recommended to mix oop syntax in your code, unless you want to learn that,

Link to comment
  On 05/11/2017 at 14:32, IIYAMA said:

It is not recommended to mix oop syntax in your code, unless you want to learn that,

Expand  

I guess yeah,
it worked but after triggering again, an error pop out on dxoutput.client.lua on this at line 5:

local message_moving_back_timer;
function dxOutputMessage(message, r, g, b)
	if (message_moving) then removeEventHandler("onClientRender", root, moveMessage); end
	if (message_moving_back) then removeEventHandler("onClientRender", root, moveMessageBack); end
	if (message_moving_back_timer and message_moving_back_timer:isValid()) then message_moving_back_timer:destroy(); end -- message_moving_back_timer
	cur_left, cur_message, cur_color = relative_width * 1440, message or "", {r or 255, g or 255, b or 255};
	message_moving_back_timer = setTimer(hideMessage, 5000, 1);
	addEventHandler("onClientRender", root, moveMessage);
	message_moving = true;
end

the error I got:

  Quote

ERROR: Attempt to index upvalue 'message_moving_back_timer' (a userdata value)

Expand  

 

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