Cant really tell whats cause it to warn you, but i guess its caused by nil?
WaitForChild returns Instance?type (aka Instance or nil) instead of Instance type, you need to do something like this
local part = workspace:WaitForChild("Part")
if part then
for _, surf in Enum.NormalId:GetEnumItems() do
...
part[surface] = "Glue"
end
end
and to be extra safe, typecast Part type to part variable
local part = workspace:WaitForChild("Part") :: Part
From perspective of compiler it doesn’t know what Surface variable represents, it can be anything and this really goes against why we use strict, we use it to make code predictable because of this you have to make sure to tell the compiler its one of the surface properties by type annotation or if statement that checks value of surface matches surface property names. Also when using WaitForChild you have to tell compiler what type its, right now you’re telling compiler to wait for an instance that is called “Part” it doesn’t know what type of instance its, it doesn’t know instance is part.
Assign the Part you are looking for first and assert the type to be a Part, then you can access the surface property without any type errors
local Part = Workspace:WaitForChild("Part") :: Part
Part.Surface = "Glue" --Is surface even a property?
yes
But why you write workspace from upper case?
Anyway please cache it
Next time dont make me suffer having to rewrite it please for god sake
local Part = workspace:WaitForChild("Part")::any
for _,surf in Enum.NormalId:GetENumItems() do
--I aint rewriting allat
end
That not what he wanted
surface is a variable
So surface for example is a “BottomSurface” e.g. Part[“ButtomSurface”]
And it accepts string instead of enum as an option
Althrough its probably bad for performance
Since its a dynamic property lookup you have to cast it to any instead of to part
If you cast it dynamically im not sure if strict typing will allow you to access those properties
Enum.NormalId is constant, not sure why you need loop.
--!strict
local part = workspace:WaitForChild("Part")
part.BottomSurface = Enum.SurfaceType.Glue
part.TopSurface = Enum.SurfaceType.Glue
part.LeftSurface = Enum.SurfaceType.Glue
part.RightSurface = Enum.SurfaceType.Glue
part.FrontSurface = Enum.SurfaceType.Glue
part.BackSurface = Enum.SurfaceType.Glue
