Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Use LocalPlayer in non-local script?

Asked by 7 years ago
local replicatedstorage = game:GetService("ReplicatedStorage")
local status = replicatedstorage:WaitForChild("StatusValue")

local meat = game.Players.LocalPlayer

while true do
    for i = 10,0,-1 do
    status.Value = "Intermission:"..i
    wait(1)
    end
    game.Players.LocalPlayer.TeamColor = BrickColor.new("Really red")
game.Players.LocalPlayer:LoadCharacter()
game.Players.LocalPlayer.TeamColor = BrickColor.new("Really red")
    for i = 120,0,-1 do
    status.Value = "Game In Progress:"..i
    wait(1)
    end
    game.Players.LocalPlayer.TeamColor = BrickColor.new("White")
game.Players.LocalPlayer:LoadCharacter()
game.Players.LocalPlayer.TeamColor = BrickColor.new("White")
    end


So, this code controls the round times and teleporting players away from and to the map. The Red team is in the game, and the white team is in the lobby. When it changes the players team, it resets them afterwards, basically teleoprting them to a diffrent spawn point.

The problem here is that This is the the serverscriptservice and in a normal script. How can i acheive something similar to .Localplayer in a non-local script?

0
Not possible Wilbob30 69 — 7y
0
It is possible... But it's about what the script need to do. In your loop it's Not Possible! MineJulRBX 52 — 7y
0
And you use LocalPlayer only. You need to make it "FindFirstChild" else it don't know who it's need to find. If you just use LocalPlayer it takes the first player it find but it can't find anyone. Not without "FindFirstChild" MineJulRBX 52 — 7y
0
Ahh, so I make it game.Players:FindFirstChild() ? User#17125 0 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Loop through each player in the game and run the code on each of them like so:

local replicatedstorage = game:GetService("ReplicatedStorage")
local status = replicatedstorage:WaitForChild("StatusValue")

while true do
    for i = 10,0,-1 do
        status.Value = "Intermission:"..i
        wait(1)
    end
    for _,plr in pairs(game.Players:GetPlayers()) do
        plr.TeamColor = BrickColor.new("Really red")
        plr:LoadCharacter()
    end
    for i = 120,0,-1 do
        status.Value = "Game In Progress:"..i
        wait(1)
    end
    for _,plr in pairs(game.Players:GetPlayers()) do
        plr.TeamColor = BrickColor.new("White")
        plr:LoadCharacter()
    end
end

If this works for you, please accept it as the answer and vote up if you feel like it. If this doesn't work or doesn't do what you wanted it to do, let me know down below in the comments with as much detail as possible.

0
Thanks for the reply General_Scripter! It worked great! User#17125 0 — 7y
0
No problem. General_Scripter 425 — 7y
Ad

Answer this question