How would I define one player instead of all the players.
Defining all players script:
local Player = game:GetService("Player")
How would I define one player instead of all the players.
Defining all players script:
local Player = game:GetService("Player")
local Player = game:GetService("Players").PlayerName
If you are using a normal script, you can get the player by events such as playeradded or playerremoving. On a local script, you can use
local player = game.Players.LocalPlayer
I tried this but it still prints until local player:
local button = script.Parent
print("Test")
local Npc = game.workspace.Npc
print("Test")
local Player = game:GetService("Players").PlayerName
print("Test")
local sticking = Player.HumanoidRootPart.Position
print("Test")
function onClick(Click)
print("Test")
wait(10)
print("Test")
Player.HumanoidRootPart.Position = Npc.HumanoidRootPart.Position
print("Test")
end
print("Test")
button.MouseButton1Click:Connect(onClick)
print("Worked!")
Also, this defines does not define all players. It defines the player service. If you want a table of all the players, you can use
Local allPlayers = game:GetService(“Players”):GetPlayers()
Is this a local script or a normal script
no you put the player’s name there
doing “.PlayerName” obviously won’t work
It depends on if its a server script or a local script. What are you trying to do with the player? Something to every player when they join, when they respawn, when they touch something or sit on something? There are different ways to find a player depending on your use case, be more specific.
We must know which script you are using, which I assume is local. You can use game.Players.LocalPlayer in a local script.
Edit: You can see whether a script is local or not by a little person in blue in the explorer menu. If there is, then It is local. Alternatively, you can check the class of the object.
Yeah, I know, I don’t know if OP knows.
LocalScript:
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
--\\ This gets the player that script is running on.
Server:
The server is not a player, you must just loop through all players if you wanna do something for each player.
Example:
local Players = game:GetService("Players")
for _, player in ipairs(Players:GetPlayers()) do
player:Kick()
end
It is a local script inside of a button inside of a screen gui
Use game.players.LocalPlayer or game:GetService(“Players”).LocalPlayer. Does the same thing.
Used
local LocalPlayer = game.Players.LocalPlayer
You can just call it player to fit the rest of the code. Otherwise change all the other players in the localscript into localplayer
I have already. there were only few “players”
use task.wait instead of wait!!!