Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] Is it possible to transform a string to a path?

Asked by
alefa03 15
4 years ago
Edited 4 years ago

Hi, i'm trying to script a liquid tank, which is built with little parts (that i've called "p1", "p2", etc...) which appear and disappear (to make the "filling/emptying" animation). When the production of the liquid is off, the liquid level in the tank should decrease only when it's used.

To make the tank emptying when the liquid is used, i've used an "if" statement. In the "if" block i've put the followning code, which basically takes the path of the part with it's initial char ("p"), and concatenates it with a NumberValue (called "Level"). The parts are 26, the NumberValue decreases each time the loop repeats the block until it reaches 0.

The main problem is that Roblox Studio does not recognise the string as a part of the path.

local PartOfLiquid = ("script.Parent.Coolant1.p" .. script.Parent.Level.Value)

print(PartOfLiquid) --Prints the string
PartOfLiquid.Transparency = 1
script.Parent.Level.Value = script.Parent.Level.Value - 1
print(script.Parent.Level.Value) -Prints the level value

Output:

script.Parent.Coolant1.p26 (Comes from "print")

Attempt to index string with 'Transparency'

Is it possible to do so somehow?

0
You cannot change the property of workspace with a string you will need something e.g. a part to reference. JesseSong 3916 — 4y
0
The part name changes when the value changes. The problem is that Roblox Studio does not recognise the string as a path. alefa03 15 — 4y
0
try local PartOfLiquid = (script.Parent.Coolant1["p" .. (tostring(script.Parent.Level.Value))]) Awesom3_Eric 157 — 4y
0
Woah! It worked thanks! alefa03 15 — 4y

Answer this question