Jump to content

Question about getLocalPlayer()


Recommended Posts

Local player is actually the client!

So server side script hasn't local player because the script is server side :)

you should use this in client side

triggerServerEvent("EventName",localPlayer) -- localPlayer = source of the event in server side

and you can receive your event from server side like this :

addEvent("EventName",true)
addEventHandler("EventName",root,
  function()
    local localPlayer = source; -- source is that player you put in the triggerServerEvent
    -- now you have the localPlayer in the server
  end
)

also, there are another methods you can use, but this is a simple example.

 

Note :

When you need to use the localPlayer in server side, you will be automatically must be using the triggerServerEvent function.

So in the logic you have to trigger an event

 

When you want to use localPlayer?

Edited by VenomNX
Link to comment
  • Scripting Moderators
20 minutes ago, VenomNX said:

Local player is actually the client!

So server side script hasn't local player because the script is server side :)

you should use this in client side


triggerServerEvent("EventName",localPlayer) -- localPlayer = source of the event in server side

and you can receive your event from server side like this :


addEvent("EventName",true)
addEventHandler("EventName",root,
  function()
    local localPlayer = source; -- source is that player you put in the triggerServerEvent
    -- now you have the localPlayer in the server
  end
)

also, there are another methods you can use, but this is a simple example.

 

Note :

When you need to use the localPlayer in server side, you will be automatically must be using the triggerServerEvent function.

So in the logic you have to trigger an event

 

When you want to use localPlayer?

Using source variable isn't safe.

function EventName()
	if client then
		outputChatBox("Hi player!", client)
	end
end
addEvent("EventName", true)
addEventHandler("EventName", root, EventName)
Quote
  • All parameters including 'source' can be faked and should not be trusted.
  • Global variable 'client' can be trusted.

https://wiki.multitheftauto.com/wiki/Script_security

  • Like 1
  • Thanks 1
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...