The scripts I have been making in studio only actually work in solo mode, but they do not work online, I know the reason for this is because all of the scripts I have made are all based on 'Player', for example to make a players torso invisible:
game.Workspace.Player.Torso.Transparency = 1
How do I make it so that 'Player' is changed to any player on the servers username? For example, if I was on the server, the script would automatically change to:
game.Workspace.mrcool2.Torso.Transparency = 1
EDIT:
In an actual concept, I have a script which is used to change the properties of an item the player is holding in their hand when it interacts with the environment, so i need the script to be able to find the player in the workspace, to find said tool, for example,
game.Workspace.Player1.Torch.Fire.Enabled
My issue is including every player in the place of 'Player1' so that the script can pick up the item in any players hand, without their username having to be manually written down in the script.
I'm sorry if this is really badly explained, it's a quite a difficult concept to explain >_<
If this is a localscript, it can be done easily.
local player = game.Players.LocalPlayer game.Workspace[player.Name].Torso.Transparency = 1
If its in a regular script, and you want this to happen when they first join, you can do this.
game.Players.PlayerAdded:connect(function(player) game.Workspace[player.Name].Torso.Transparency = 1 end)
There are you ways of specifying the player/player(s). The easiest one would be to create a local script, place into the StarterPlayerScripts
file (or any client side service). It would look something like this:
player = game.Players.LocalPlayer --the local player stands for the client (player) who is running the script repeat wait() until player.Character ~= nil --this wait and pause the next few lines of script until the players character loads player.Character.Torso.Transparency = 1 --NOTE that you can only grab the torso from the character of the player
The second way of doing it is to use a server side script. There's a specific way of doing this. You cant just grab the LocalPlayer
like we did in the local script. Instead, we have to locate the specific child from the players file (theplayer
from the Players
file). To do this, we create a table. A table is a list of values that is represented by one variable (an array). Then, we iterate through that table. What this does is it runs through all of the values in the table, one by one. This is represtented by v
. Finaly for each value, we set the players torso transparency to 1. It should look something like this:
players = game.Players:GetChildren() --this returns a list of all the players in the `Players` file for i,v in pairs(players) do -- this is what an iteration should look like repeat wait() until player.Character ~= nil --we wait until the game has loaded the character appearance player.Character.Torso.Transparency = 1 end
Now if your trying to speciy a specific player, you need specific conditions/arguments. For example, if youd only want o set the transparency of one player's torso using certain conditions, you'd use a bool
(If Then Statement).
I hope this answered your question. If you have any other questions, please put a comment below. Otherwise, I have a list of helpfull links below. Your welcome!!!
HELPFUL NOTES
-The only way to access the player is from the "Players" game service, not the Workspace -If you are more of an experienced scripter, I suggest you use server scripts. Local Scripts can be limited and for security it's easier for them to be hacked.
LINKS:
Tables: http://wiki.roblox.com/index.php?title=Table
Booleans: http://wiki.roblox.com/index.php?title=Boolean
LocalScripts: http://wiki.roblox.com/index.php?title=API:Class/LocalScript
LocalPlayer Example: http://wiki.roblox.com/index.php?title=API:Class/Players/LocalPlayer
The player: http://wiki.roblox.com/index.php?title=API:Class/Player
The Players Service: http://wiki.roblox.com/index.php?title=API:Class/Players