StringValue

사용되지 않는 항목 표시

A StringValue is an object whose purpose is to store a single Lua string. The length of the string can't be more than 200,000 characters (this will cause a "String too long" error). Like all "-Value" objects, this single value is stored in the Value property. The Changed event for this (and other objects like it) will fire with the new value being stored in the object, instead of a string representing the property being changed.

If the string is too long to be displayed in the Value field within Properties window, it will partially show the string contents followed by an ellipsis (...).

코드 샘플

Changed Event

-- Demonstrate the Changed event by creating a Part
local part = Instance.new("Part")
part.Changed:Connect(print)
-- This fires Changed with "Transparency"
part.Transparency = 0.5
-- Similarly, this fires Changed with "Number"
part.Name = "SomePart"
-- Since changing BrickColor will also change other
-- properties at the same time, this line fires Changed
-- with "BrickColor", "Color3" and "Color3uint16".
part.BrickColor = BrickColor.Red()
-- A NumberValue holds a double-precision floating-point number
local vNumber = Instance.new("NumberValue")
vNumber.Changed:Connect(print)
-- This fires Changed with 123.456 (not "Value")
vNumber.Value = 123.456
-- This does not fire Changed
vNumber.Name = "SomeNumber"
-- A StringValue stores one string
local vString = Instance.new("StringValue")
vString.Changed:Connect(print)
-- This fires Changed with "Hello" (not "Value")
vString.Value = "Hello"

속성

Value

병렬 읽기

The stored string.

메서드

이벤트

Changed

Fired whenever the StringValue.Value of the StringValue is changed. It will run with the new value being stored in the argument object, instead of a string representing the property being changed.

This event, like other changed events, can be used to track when an StringValue changes and to track the different values that it may change to.

For instance, this may be useful in games that rely on StringValues to track values such as NPC or item names.

Equivalent changed events exist for similar objects, such as NumberValue and BoolValue, depending on what object type best suits the need.

매개 변수

value: string

The new value after the change.


코드 샘플

How to Use StringValue.Changed

local value = Instance.new("StringValue")
value.Parent = workspace
value.Changed:Connect(function(NewValue)
print(NewValue)
end)
value.Value = "Hello world!"