Skip to Content

Settings with values

Replace hard-coded constants with value objects so a script can be configured from Properties.

Hard-coded version

This speed pad hard-codes its speed and duration:

local pad = script.Parent

pad.Touched:Connect(function(player)
	player.Character.WalkSpeed = 32
	task.wait(3)
	player.Character.WalkSpeed = 16
end)

Changing either number requires editing the script.

1. Add value objects

Right-click the script in the Explorer and choose New NumberValue. Name it Speed with a value of 32. Add a second NumberValue named Duration with a value of 3.

2. Read the values

local pad = script.Parent

local function setting(name, default)
	local item = script:FindFirstChild(name)
	if item then
		return item.Value
	end
	return default
end

pad.Touched:Connect(function(player)
	player.Character.WalkSpeed = setting("Speed", 32)
	task.wait(setting("Duration", 3))
	player.Character.WalkSpeed = 16
end)

setting returns the value if the child exists and a default otherwise. Values are read on every call, so runtime changes apply immediately.

3. Reuse

Duplicate the pad and set the copy's Speed to 50. Both pads share the same script with different configuration.

Values in models

For models, parent the values to the model itself. The Toolbox zombies use this layout:

local zombie = script.Parent
local humanoid = zombie.Humanoid

humanoid.MaxHealth = zombie.Health.Value
humanoid.Health = humanoid.MaxHealth
humanoid.WalkSpeed = zombie.Speed.Value

See Values for every value class, the Changed event and Toolbox model parameters.

On this page