Cookbook (Chapter 8)

From Legacy Roblox Wiki
Jump to navigationJump to search

Local Parts

Problem

You want a part that can only be seen by one person.

Solution

Use a local part.

Instance.new('Part', Workspace.CurrentCamera).Position = Vector3.new(0, 10, 0)

Discussion

First of all this must obviously be in a LocalScript in the correct directory in order to work. See Recipe 4.6 for more details on this. We're creating a new part inside of the Camera then editing its size. How does this work? All descendants of the Workspace get rendered as parts. Since the Camera is inside the Workspace and is local to the client, that means that the part is also located only on the client side. Therefore this makes it so it only exists on one client creating what's called a local part.

This is quite useful for VIP doors. If you want a non-killing VIP door, other people besides the VIPs may be able to slip in while the door is open (usually a 3 second opening). By using local parts in order to block VIP access to only certain people, you can create a full proof VIP door.

Using CameraSubject

Problem

You want to focus your camera on another part.

Solution

Use the CameraSubject and CameraType properties.

Workspace.CurrentCamera.CameraSubject = Workspace.Player.Head
Workspace.CurrentCamera.CameraType = Enum.CameraType.Follow

Discussion

The CameraSubject property sets what the Camera is looking at. This is set to game.Workspace.Player.Head which is what we want to look at. Then we set CameraType which is how the Camera is going to interact with its subject to be “Follow”. This way we can zoom, and rotate with the subject.

Reflection Metadata

I've you've ever gone exploring in the ROBLOX application directory you may have come across an XML file called ReflectionMetadata.xml. The RMD for short is used to determine what objects are shown in the Explorer window, as well as what objects are shown in the object browser and their summary. We already know that there are services as children of the game, however we don't see them in the Explorer. This is because the RMD is not edited to show us them. How do we start seeing more interesting objects?

We edit the RMD. Do note that editing your RMD may break your ROBLOX application. Reinstalling will clean the RMD and allow you to play once more. Anaminus publishes an updated RMD to his alt here: http://www.roblox.com/User.aspx?ID=6449825. I suggest that you set this user as a “best friend” in order to get RMD updates in your feed. In the models of that account you will see past RMD edits. In order to edit your RMD you must open the RMD file. Here is where you can find it:

XP: \User\Local Settings\Application Data\RobloxVersions\version-xxxxxxxxx
Vista: \User\AppData\Local\Roblox\Versions\version-xxxxxxxxx
Win7: \User\AppData\Local\Roblox\Versions\version-xxxxxxxxx

Open up ReflectionMetadata.xml and paste in either your own edited version, or Anaminus's RMD. After saving and restarting ROBLOX studio, you should see all the game services (and hidden instances) in your explorer.

Testing Chatted Event

Problem

You want to test a script that uses the Chatted event in Solo.

Solution

Use the a StringValue with the .Changed event.

local p = game.Players.Player
Workspace.Value.Changed:connect(function(msg)
	-- etc...
end)

Discussion

You may have noticed that in Solo testing, there is no area where you can type to test scripts that involve the Chatted event. Therefore instead of doing:

game.Players.PlayerAdded:connect(function(p)
	p.Chatted:connect(function(msg)
		-- etc...
	end)
end)

We could use the code posted in the solution. So when you change the StringValue's value, it will simulate the Chatted event.

Note: You could also use the Player object's SetSuperSafeChat method, with false for argument. Doing this will make the chat bar appear.

game.Players.Player:SetSuperSafeChat(false)