User:Anaminus/PlayerEntered: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mr Doom Bringer
m (PlayerEntered moved to User:Anaminus/PlayerEntered)
>Anaminus
(Blanked the page)
 
Line 1: Line 1:
==Introduction==


You know how when a player enters, they always seem to be... themselves.... I'm sure you new scripters have always wanted to do some interesting things to your players when they enter! Remove their body parts...... change their shirt ID.... remove their face..... Well, this is actually quite simple if you follow this easy guide on editing your player! Let's begin, shall we?
==Getting Started- How to make this script activate in the beginning==
With most good scripts, each one needs a function. Then after that some basic lines to support the function... and then the fun stuff! Well, this step will basically get us "Prepped" for the fun stuff. First of all, we need a function. And here's that function:
<pre>function onPlayerRespawned(newPlayer)
</pre>
Now that's saying what happens when the player respawns. Simple, eh? When doing a script affecting a player, you really need more "Junk" at the end of the script then beginning. Now we basically just have to tag the character so we can edit it. So basically, these are the 2 lines we have so far:
<pre>function onPlayerRespawned(newPlayer)
local char = newPlayer.Character</pre>
To put it in simple terms for these two lines:
When a player enters/respawns (Whatever you want to say, but don't change it in the script!), we are tagging the players character, or bascially writing into game.Players.newPlayer.Character, but in PlayerEnter form. So now let's go onto the fun stuff >:D
==Editing the player, what we've really wanted this entire time :D==
Ok, now we have that function stuff out of the way. So now let's edit the player!!! For starting purposes, im going to show you how to remove everyone's legs and arms when they enter :D Now, we can tag the players body parts... NO! Or we can just do a findFirstChild and remove it... NO!!!! I'm going to show you an EXTREMELY fast way to edit these body parts!!! Now since we tagged the newPlayer "char" then that's how it's going to work. Got it? Ok, great! This line is going to remove the players Left Leg.
<pre>char["Left Leg"]:Remove()
</pre>
See how shortened up that line was? Much faster then char:findFirstChild("Left Leg"), isn't it? Now then, guess we should remove the arms and other leg, shouldn't we? Ok, yes, we should! By following that simple way of removing body parts, let's continue!
<pre>char["Left Leg"]:Remove()
char["Right Leg"]:Remove()
char["Left Arm"]:Remove()
char["Right Arm"]:Remove()
</pre>
Ok, I understand, only removing Legs and Arms is kinda lame, isn't it? Well don't worry, with good practice, you can make some really fun stuff from this :D
==The End of the Script: The Tricky and Hard-To-Remember Stuff==
Now, this goes with what I said in the beginning of this tutorial- There are more lines that go with the function at the end of the script than the beginning of the script. What these few lines do are connecting the onPlayerRespawned function, checking the property it is effecting, and if the property is a character (You), then it will connect a function onPlayerEntered with it. Well, I'll just show you those last lines:
<pre>function onPlayerEntered(newPlayer)
newPlayer.Changed:connect(function (property)
if (property == "Character") then
onPlayerRespawned(newPlayer)
end
end)
end
game.Players.PlayerAdded:connect(onPlayerEntered)
</pre>
Now when making this script, you'll notice there's a ) at the end of the second end. This is extremely important! If you don't have it there THE SCRIPT WILL NOT RUN AT ALL! So always remember it!!!!
==The Final and Finished Script Put TOGETHER==
Ok, now then, a quick review. We have the function and tagging that effects the player just as they enter. We have the lines that remove the players arms and legs when they enter. And we have those last few lines that simply check to see if its editing a player as they respawn, and then connect everything with the very last line. So what does the FINAL script look like? This!!!!
<pre>function onPlayerRespawned(newPlayer)
local char = newPlayer.Character
char["Left Leg"]:Remove()
char["Right Leg"]:Remove()
char["Left Arm"]:Remove()
char["Right Arm"]:Remove()
end
function onPlayerEntered(newPlayer)
newPlayer.Changed:connect(function (property)
if (property == "Character") then
onPlayerRespawned(newPlayer)
end
end)
end
game.Players.PlayerAdded:connect(onPlayerEntered)
</pre>
Well, that was a simple and easy tutorial, wasn't it? Now go have fun with your players as you edit them!!! :D

Latest revision as of 02:17, 5 May 2012