Experiments
This API is used to read the experiment groups of players and the server, and to set the properties experiments target on.
For more information about Experiments, visit the Experiments Guide.
local Gamebeast = require(game:GetService("ReplicatedStorage"):WaitForChild("Gamebeast"))
local GamebeastExperiments = Gamebeast:GetService("Experiments") :: Gamebeast.ExperimentsServiceEnrollment happens automatically. The SDK assigns players when they join, and the values returned by Configs already include each player's group changes. You don't need this service to run an experiment. Use it to read assignments, for display, analytics or debugging, and to set the properties your experiments target.
How assignments stay current
The SDK requests a player's groups when they join, again when their targeting properties change, and then every 30 seconds while they're in the server. That periodic refresh is how a change made on the dashboard, such as moving a player to another group by hand, reaches players already in game. Change how often it runs with the assignmentRefreshRate setting.
A player can be in several experiments at once, as long as they change different keys.
Types
ExperimentAssignment
type ExperimentAssignment = {
experimentId: number,
experimentName: string,
groupId: number,
groupLabel: string, -- The name of the group.
unitType: "user" | "server", -- Whether a player or the server is assigned.
source: string?, -- How the group was chosen: "weightedHash", "roundRobin" or "manual".
}ExperimentPropertyValue
-- Lists hold one type of value, at most 100 items.
type ExperimentPropertyValue = string | number | boolean | { string | number | boolean }Assignments
:GetAssignmentsForPlayer(player)
{ExperimentAssignment}return type
Returns the player's active assignments, ordered by experiment ID. Empty until their first assignment has resolved, shortly after they join.
playerPlayerThe player to read assignments for.
Usage
for _, assignment in GamebeastExperiments:GetAssignmentsForPlayer(player) do
print(player.Name, "is in", assignment.groupLabel, "of", assignment.experimentName)
end:GetServerAssignments()
{ExperimentAssignment}return type
Returns the server's active assignments, for experiments that assign whole servers.
Usage
for _, assignment in GamebeastExperiments:GetServerAssignments() do
print("Server is in", assignment.groupLabel, "of", assignment.experimentName)
end:OnAssignmentsChangedForPlayer(player, callback)
RBXScriptConnectionreturn type
Calls callback with the player's full list of assignments whenever it changes. The connection is
disconnected automatically shortly after the player leaves, after a last call with their assignments
cleared.
playerPlayerThe player to listen to.
callback(assignments : {ExperimentAssignment}) -> ()Called with the player's updated assignments.
Usage
GamebeastExperiments:OnAssignmentsChangedForPlayer(player, function(assignments)
print(player.Name, "is now in", #assignments, "experiments")
end):ObserveAssignmentsForPlayer(player, callback)
RBXScriptConnectionreturn type
Like :OnAssignmentsChangedForPlayer, but also calls callback once the player's assignments are
first resolved, even if they aren't in any experiment.
playerPlayerThe player to observe.
callback(assignments : {ExperimentAssignment}) -> ()Called with the player's assignments.
Usage
game:GetService("Players").PlayerAdded:Connect(function(player)
GamebeastExperiments:ObserveAssignmentsForPlayer(player, function(assignments)
for _, assignment in assignments do
print(player.Name, "is in", assignment.groupLabel, "of", assignment.experimentName)
end
end)
end):OnServerAssignmentsChanged(callback)
RBXScriptConnectionreturn type
Calls callback with the server's full list of assignments whenever it changes.
callback(assignments : {ExperimentAssignment}) -> ()Called with the server's updated assignments.
Usage
GamebeastExperiments:OnServerAssignmentsChanged(function(assignments)
print("Server is now in", #assignments, "experiments")
end)Targeting properties
Experiments can target players on properties. The SDK reports these standard Roblox properties on its own, when an experiment needs them:
| Property | Values |
|---|---|
device | mobile, console, pc, vr, unknown |
deviceSubType | tablet, phone, xbox, playstation, unknown |
inputType | keyboard, gamepad, touch, unknown |
country | ISO 3166-1 country code, such as US |
language | ISO 639-1 language code, such as en |
placeId | The place the server is running |
placeVersion | The published version of that place |
Device and input type come from the player's client, so the client must call Gamebeast:Setup() too.
To target on your own data, set properties with the methods below. Each value must be a string, number, boolean, or a list of one of those types with at most 100 items. A player or the server can have at most 100 properties, with names up to 128 characters. The SDK warns and ignores any property outside these limits.
Set a player's properties as soon as their data loads. Changing a property requests their groups again, so a late property can move a player into an experiment partway through their session.
:SetPlayerProperties(player, properties)
voidreturn type
Sets properties for a player, merged with any set before.
playerPlayerThe player to set properties for.
properties{[string] : ExperimentPropertyValue}The properties to set.
Usage
GamebeastExperiments:SetPlayerProperties(player, {
vip = true,
level = 12,
tags = { "beta", "founder" },
}):SetPlayerProperty(player, key, value)
voidreturn type
Sets one property for a player. Pass nil to clear it.
playerPlayerThe player to set the property for.
keystringThe property's name.
valueExperimentPropertyValue?The property's value, or nil to clear it.
Usage
GamebeastExperiments:SetPlayerProperty(player, "level", 13):GetPlayerProperties(player)
{[string] : ExperimentPropertyValue}return type
Returns a copy of the properties set for a player.
playerPlayerThe player to read properties for.
:SetServerProperties(properties)
voidreturn type
Sets properties for the server, merged with any set before. Server properties also apply to every player in the server. If a player has a property with the same name, theirs wins.
properties{[string] : ExperimentPropertyValue}The properties to set.
Usage
GamebeastExperiments:SetServerProperties({ region = "eu", mode = "ranked" }):SetServerProperty(key, value)
voidreturn type
Sets one property for the server. Pass nil to clear it.
keystringThe property's name.
valueExperimentPropertyValue?The property's value, or nil to clear it.
:GetServerProperties()
{[string] : ExperimentPropertyValue}return type
Returns a copy of the properties set for the server.
Deprecated
:GetGroupForPlayer(player)
ExperimentGroupMetadata?return type
Deprecated. A player can now be in several experiments at once, and this returns only the first.
Use :GetAssignmentsForPlayer instead.
Returns the player's first assignment, or the server's if the player has none, as
{ experimentName: string, groupName: string }. Returns nil if neither is in an experiment.
playerPlayerThe player to get the group for.