I have tried many ways like using local script but still doesn't work so I try to use normal script again. For the local script the LocalPlayer works but my other script doesn't work, it stops. Maybe it's because I put all of the script together. I'm confused about the local script and LocalPlayer. The script is for minigame that I am making. So here's my script :
01 | --start |
02 | game.Players.ChildAdded:wait() |
03 | --variables |
04 | Map 1 = game.ServerStorage.Maps.Arena 1 |
05 | NotificationGui 1 = game.Workspace.StatusBar.Gui 1. TextBox.Text |
06 | NotificationGui 2 = game.Workspace.StatusBar.Gui 1. TextBox.Text |
07 | local Player 1 = game.Players.LocalPlayer |
08 | Winner = "None" |
09 | WinnerFound = false |
10 | enabled = true |
11 | Reciver = game.Workspace.Spawn.Spawn 1 |
12 |
13 | --Reciver Vars |
14 | Spawn 1 o = 0 |
15 | Spawn 2 o = 0 |
If it's in a LocalScript:
You're waiting for a Player to join. Unfortunately, when you join that event will not fire for LocalScripts listening to it. That in turn means that unless another player joins the game, the LocalScript is never going to get past line 1.
If it's in a Script
You can't use Players.LocalPlayer
in a Script, because it simply doesn't know anything about it on the server. You can get the first Player to join if you replace your first line with
1 | local Player 1 = game.Players.PlayerAdded:wait() |
Which will assign Player1
to the first Player to join the server. Be aware that this may or may not play nice with how you expect your game to work, and how or where you do stuff is down to you.
In studio, it makes everything run through the server (studio wise). In-game, you must use a local script when connecting to a local player and do not use localscripts for anything other than the client's children. This script would not work with multiple users if you're attempting to use it in a local script and same with a server script.
Local Reason: It'd run on all clients and be different for everyone causing your game to look very glitchy and buggy because instead of running one time, it'll be running several times through several clients.
Server Reason: You cannot connect to a local player through server scripts, if you're attempting to grab players I recommend you use
1 | for i,v in pairs (game.Players:GetChildren()) do |
2 | print (v.Name) -- v represents the player. |
3 | end |