Finding The Local Player Via Script

Hey guys Im trying to find the Local Player so that it check if the player is in Killers Team it give them a weapon which is in Replicate Storage I dont get any errors but code doesnt work a lttle help would be really nice


i

Is that a local script or a server script?

Idkkkkk what else to typeee here Roblox should remove this

But yuh it’s a Server Script

i’m not entirely sure what you’re trying to do here, but you cannot use Players.LocalPlayer on the Server, so you’ll have to rethink your logic a bit

if you can provide more information with what exactly you’re trying to achieve, I may be able to provide better advice

So what Im trying to achieve maybe pretty easy for some scripters soo I put a Tool in RS and I want that when someone clicks the Killers Team button it will clone the weapon and put it in their backpacks after the delay of course

when you say killers team, i’m guessing this is a UI button or a click detector?

in which case, you will be able to set up some events that connect to these, and you should be able to easily retrieve the player from these events

I would appreciate if you dont feed me your own code as I want to better myself please tell me my leaks and flawsesses

yes it’s a Ui Button I tried using game.Players.PlayerAdded

yes im purposefully not providing code examples as I think it is better for people to figure the coding part out themselves; i will just try to point you in the right direction.

i noticed you said it is a UI button. please take a look at this link for some information on TextButtons, specifically the MouseButton1Click event, which may be the one you want to use.

edit: typo

1 Like

As @plagueus mentioned, the LocalPlayer property of the Players service can only be used in a local/LocalScript environment. Your first step would be to change this to a LocalScript then.
Another reason why your code wouldn’t work is because you’re just checking the player's TeamColor once, when the script first starts running.

I would appreciate if you dont feed my your own code as I want to better myself please tell me my leaks and flawsesses

I understand you don’t want to be spoonfed but is it okay if I write you example code that wouldn’t necessarily work if you just copied it, but would work if you refactor your code based on it?

Ok It’s fine I will try and check where I went wrong with it

If its a button then you’d have to make a localscript to detect when its clicked then fire a remoteEvent to the server when it is

For the Clicking Side it works The only thing that doesnt work is giving players on the killing team the Tool

You have to fire a remoteEvent to the server and you can get the LocalPlayer on the server through it
Btw if you’re changing the team in a localscript it probably only appears for them only

Yes cause Each player will join the game at his own time and if he closes the Ui he will only close his side of the Ui’s

I get that but you should change the player’s team on the server otherwise the weapon clone wont work bc the server still thinks they’re on the other team

Aight I get that I will try that cause I want to avoid as much memory leak in the game Should I put it in the same script as the WeaponCloneHandler?

Well you’d still need to know when they click the button to change team

Ight I Understand now but you do know that with the local script I wrote it detects when I chamge the team and it changes it

But you talkd about looping through players in game How would that work