Scripting Helpers is winding down operations and is now read-only. More info→
← Blog Home

Exploring new API members to do new, cool things in your game!

In order to keep yourself updated, it's a good practice to read the API differences. Anaminus has created a very good utility for this. You can find it here.

CameraMinZoomDistance and CameraMaxZoomDistance

Let's take a look at some of the new properties which we can use in Roblox. One of the coolest things I have found so far is the CameraMaxZoomDistance and the CameraMinZoomDistance properties. You have probably played Apocalypse Rising. Remember that when you zoom out a message pops up that you have to zoom in? We don't have to do this anymore. We can a now use those properties. These are members of the Player Instance. For example, this will limit your players' camera:

game.Players.LocalPlayer.CameraMaxZoomDistance = 10

FieldOfView

This property is not new, but has updated its bounds. We can now supply extreme values of FieldOfView. Try setting the FieldOfView property of game.Workspace.CurrentCamera to 180, for example, or to 1. It now supports extreme zooming!

ReplicatedFirst

One of the newest additions is ReplicatedFirst. The last time I checked it, it didn't work yet, but Roblox engineers are working on it. If you put something in ReplicatedFirst (a game service) then you are sure that these instances get replicated, well, first. You can even override the default game loading screen with it by setting the RemoveDefaultLoadingScreen property.

ToolPunchThroughDistance

This is a property of a SurfaceGui. You can set it on which distance the tool mouse events (such as mouse clicked) are not fired anymore. Instead, the events of the SurfaceGui will fire, such as the MouseButton1Click event of a TextButton.

CameraOffset

This is a property of Humanoid. Normally, if you completely zoom in you always get in the characters' head. Using this property you can set the offset of the camera as a position. For example, if you want the camera to be 5 studs higher than the character, you can set it to Vector3.new(0,5,0).

PrimaryPart

Models always had a PrimaryPart property. We can now move this PrimaryPart around without changing the offsets of the other parts in the model. In other words, you can use these new methods to move a model around without doing all these fancy CFrame lines. You first set the PrimaryPart property of the model, and then use the SetPrimaryPart method.

HealthDisplayDistance and NameDisplayDistance

If you ever tried to remove the humanoid health bar or the name tag of a humanoid, you probably remember the obscure method on how you had to do that. If you don't: You had to clone the head, make the original head transparent and then weld the new head to the old head. Extremely strange! We finally got a clean method to hide names and health. Just set these properties (a member of Humanoid) to hide your health and name tags. Awesome!

StateChanged

Humanoids have a lot of events. Running fires when the player is walking: FreeFalling is fired when someone is falling down. If you wanted to detect if someone was walking, you had to connect to ALL events and then only set walking to true for the right events. We now have an event for this: StateChanged. This is also an event of humanoid. StateChanged fires with an enum as first arguments, which tells you what the humanoid is now doing. For example, i could first fire with Enum.HumanoidStateType.Running and then fire with Enum.HumanoidStateType.FreeFalling. You then know that the humanoid is falling down after he has walked (and thus not that someone has shoved him down somewhere, but that the player decided himself to fall down, or that this accidentally happened!)

UserInputService

If you connect to the KeyDown event of Mouse and tried to use special keys (such as the Ctrl key), you have probably noticed that the 2 key and the Ctrl key fire with the same byte codes. In other words: it's not known if someone has pressed Ctrl or 2, which is extremely annoying. Luckily, we now have UserInputService: we can use the InputBegan event to detect which key has been fired. The first argument is an InputObject. This has the KeyCode property which holds an Enum. Via this Enum you can detect which key has really been pressed. Is it Enum.KeyCode.LeftControlor is it Enum.KeyCode.Two? We can finally distinguish between those two keys.

The os library

I'll be wrapping up this blog post with the os library. It has a handy function: os.time. This returns a time which theoretically should be the same on every system it is called on. This is other than tick, which returns a local time which is else on computers or servers in different time zones. You can use os.time on server to create timestamps and for example detect how much time it has taken for a certain player to replay your game. Think about awarding weekly bonusses for people who have been playing for 7 consectutive days.

Have you found some other cool API members which people should know about? Post them in the comments!

Posted in Scripting Tips

Commentary

Leave a Comment

Usering says: July 19, 2014
There are now some awesome new mouse API's that should be added to this as well.
xxracerdudexx says: October 4, 2014
The os library is the best, but when I looked up the os.time() function it was too confusing. Can anyone explain it?