How to use LocalPlayer


  • I think this is a very obvious thing what this does, but apparently not. Multiple people use this wrong. It always get me confused and stuff why people do not understand this.

    The error I see is using LocalPlayer on a serverscript. Here is an illustration of how the server would act.
    0_1506379778093_example.PNG

    It'd be really confused, as it does not know what player it is supposed to pick. However, localscripts can access this as it is a descendant of a player object.
    Code cannot read your mind. That is why you have to type it all out. So, instead of doing

    kick player with message saying haha i kicked you hacker
    

    you'd have to do

    game.Players.ARandomHacker:Kick('haha i kicked you hacker')
    

    I hope this helps you, and if you see anyone using LocalPlayer incorrectly, please use this short, understandable, tutorial.


  • @hiimgoodpack I like this tutorial, but it shouldn't need to be made. LocalPlayer should be a good enough indication, anyways.


  • @Thundermaker300 But people still don't use it correctly! I don't understand how this is so complicated, but apparently it is. Just look at any question that says "Works in studio but not online?" probably used LocalPlayer wrong. For example, like https://scriptinghelpers.org/questions/48190/sword-works-inside-studio-but-not-when-uploaded-to-the-site


  • @hiimgoodpack I see you were kind enough to make a forum post mocking my question. Your assumption is I don't know how to use LocalPlayer correctly. In which case, if you see it used incorrectly, then please, point it out without the condescension. The users who post here are not expert programmers, we make mistakes, sometimes incredibly obvious and stupid ones to more skilled coders like yourself, otherwise why would we post our questions here? The common response seems to be, "get good." Unfortunately, not all of us have that natural knack or easily understand the obtuse wikis and need to be lead to water and have our heads shoved in to fully understand.

    However, as I pointed out for my particular question that you bring up here - the Swords work fine, in server, and online when picked up off the map. The problem occurs when they're cloned into the player's backpack after the DataStore loads. The same exact sword/script that works when a player picks it up from the map, does not work. But other items, such as guns and potions, do work as intended. There are no error outputs, the swords don't swing, there are no print outs. Yet, again, when swords are picked up, they work fine.

    As I mentioned, I'm sure there's an obvious solution here, but I don't see it, nor have the people who do understand this stuff better than me that I have asked. Which again, is why I asked - for help. If you have any suggestions, they're much appreciated. Thank you.


  • This post is deleted!

  • @Never2Humble when I posted this a day before you... You know, I haven't scripted a time machine yet.


  • @hiimgoodpack I dunno man, I've seen some of your code, its pretty great. I wouldn't bet against you being able to script a time machine.

    Apologies - you're correct about the forum posting date being prior to your response. As I'm sure you know, its incredibly frustrating knowing that there's an obvious solution to your scripting problem, and you just don't see it. I'm gonna change my script around to be a function that grants items on the server side...but I'm still baffled why it worked fine for some Tools, and not others.


  • Update: I've made a tutorial similar to this found here. Rather than just talking about LocalPlayer, it talks about Server and clients in general.

Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.