Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

6 comments

0

What are you even talking about OBenjOne xD He has it right for the most part.

0

Can't you see that f was defined? Simply it wasn't found.

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

0

Oops this is why I comment not answer cause I'm always wrong

0

This why I never answer cause I don't look close enough

0

I'm just going to leave this question and try to forget I ever said anything

2 answers

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

Tell me if it works!

3 comments

0

it didn't

0

well then are you sure there ACTUALLY IS an object in the workspace that has the same name as stage

0

im sure

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.

4 comments

0

Theres a part named after the stage

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?

0

whats your discord

0

LegitmateTrades#0957

This discussion is preserved as it was. New answers, comments, and votes are closed.