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

Is it possible to find a part in the workspace with a intvalue?

Asked by 5 years ago

For example if you were developing a obby game, each stage would be named after the number the stage represents like stage 1 would be named 1. I tried to made a script that would take the stage of the player then find it in the workspace but don't understand what i did wrong in this script that makes error. ERROR:attempt to index upvalue 'f' (a nil value) - line 7

local player = game.Players.LocalPlayer
local ls     = player.leaderstats
local Stage  = ls.Stage
local f     = game.Workspace:FindFirstChild(Stage.Value)

Stage.Changed:connect(function()
f.BrickColor = BrickColor.new("Bright red")
print(Stage.Value)


end)
0
What are you even talking about OBenjOne xD He has it right for the most part. LegitmateTrades 159 — 5y
0
Can't you see that f was defined? Simply it wasn't found. User#19524 175 — 5y
0
Print f real quick before the Brick Color part to see if it still finds nil, print out Stage.Value as well and confirm that it has a counterpart that is named exactly what the value is in the workspace LegitmateTrades 159 — 5y
0
Oops this is why I comment not answer cause I'm always wrong OBenjOne 190 — 5y
View all comments (2 more)
0
This why I never answer cause I don't look close enough OBenjOne 190 — 5y
0
I'm just going to leave this question and try to forget I ever said anything OBenjOne 190 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

You can do local f = game.Workspace:FindFirstChild(tostring(Stage.Value))

Tell me if it works!

0
it didn't Handsomebud 113 — 5y
0
well then are you sure there ACTUALLY IS an object in the workspace that has the same name as stage radusavin366 617 — 5y
0
im sure Handsomebud 113 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Okay so print the f variable by using print(f) before you try to set the brick color, if it comes up as nil then print Stage.Value, if it comes up as nil make sure Stage.Value is properly defined, if it does not come up as nil and comes up with the number you want make sure there is a part in workspace Called EXACTLY what the Int Value prints.

0
Theres a part named after the stage Handsomebud 113 — 5y
0
Did you print out all those values and confirm what I said? If so would you like to add me on Discord and try to sort this out? LegitmateTrades 159 — 5y
0
whats your discord Handsomebud 113 — 5y
0
LegitmateTrades#0957 LegitmateTrades 159 — 5y

Answer this question