Part is not a member even when it clearly is

Im trying to make a bridge that activates when a cube touches a pad

I keep having a problem where i made a variable “bridge” but when i try to set a part’s transparency that’s a child of “bridge” it gives me an error saying that “PlankShadow is not a valid member of Script “Workspace.Rooms.Room4.Bridge””.

code:

local cube = script.Parent.BridgeCube

script.Parent.BridgePad2.CubeSpot.Touched:Connect(function(hit)
	if hit.Name == "BridgeCube" then
		script.Parent.BridgeSpawn.Playing = true
		
		cube.Color = Color3.fromRGB(71, 71, 71)
		cube.CanCollide = false
		for i = 1,10,1 do
			cube.Transparency = cube.Transparency + 0.1
			wait(0.05)
		end
		cube:Destroy()
		
		wait(0.5)
		local bridge = script.Parent.Bridge
		bridge.PlankShadow.Transparency = 0.5
		
		local Y = 16.609
		for i = 1,25,1 do
			bridge.PlankShadow.Position = Vector3.new(-216.552, Y, 30.625)
			Y = Y - 0.25
			bridge.PlankShadow.Position = Vector3.new(-216.552, 11.609, 30.625)
			wait(0.02)
		end

		bridge.PlankShadow:Destroy()
		bridge.plank.CanCollide = true
		bridge.plank.Transparency = 0
		
		script:Destroy()
	end
end)

Error message:
Ekrānuzņēmums 2021-07-03 113619

Explorer:
Ekrānuzņēmums 2021-07-03 113916

I’ve tried using WaitForChild and FindFirstChild, i tried rewriting it but nothing i tried fixed it

Im not sure why it worked before but doesn’t work this time.

My guess is it’s leading to the script named Bridge and not the model named Bridge. Change the script name and it should work.

It fixed it!!

I don’t know how i didn’t spot that.

1 Like