User:Anaminus/PlayerEntered: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Intile
No edit summary
 
>Intile
No edit summary
Line 40: Line 40:
==The End of the Script: The Tricky and Hard-To-Remember Stuff==
==The End of the Script: The Tricky and Hard-To-Remember Stuff==


Now, 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 is basically 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 thos lats lines:
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)
<pre>function onPlayerEntered(newPlayer)
Line 53: Line 53:
</pre>
</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 remeber it!!!!
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==
==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 veyr last line. So what does the FINAL script look like? This!!!!
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)
<pre>function onPlayerRespawned(newPlayer)
Line 78: Line 78:
</pre>
</pre>


Well, that was a simple and easy tutorial, wasn't it? Now go have fun with your players as they edit them!!! :D
Well, that was a simple and easy tutorial, wasn't it? Now go have fun with your players as you edit them!!! :D
 
07:45, 18 November 2007 (CST)Intile07:45, 18 November 2007 (CST)
 
(Will be fixing typos soon)

Revision as of 16:47, 18 November 2007

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 entered! 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:

function onPlayerRespawned(newPlayer)

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:

function onPlayerRespawned(newPlayer)
	local char = newPlayer.Character

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.

char["Left Leg"]:Remove()

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!

char["Left Leg"]:Remove()
char["Right Leg"]:Remove()
char["Left Arm"]:Remove()
char["Right Arm"]:Remove()

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:

function onPlayerEntered(newPlayer)
		newPlayer.Changed:connect(function (property)
				if (property == "Character") then
						onPlayerRespawned(newPlayer)
				end
		end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

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!!!!

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)

Well, that was a simple and easy tutorial, wasn't it? Now go have fun with your players as you edit them!!! :D