Basic Script Error

I am trying to index a BasePart called CoinOrb inside a certain script. But it gives an error saying It is not a valid member of local script...

Code:

game:GetService('ReplicatedStorage').ChestEvents.ReleaseOrbs.OnClientEvent:Connect(function(pos)
	local TS = game:GetService('TweenService')
	local player = game.Players.LocalPlayer
	local Orb2 = script.CoinOrb
	local Orb = Orb2:Clone()

Hierarchy-
image

Help is really appreciated.

local Orb2 = script:WaitForChild("CoinOrb")
game:GetService('ReplicatedStorage').ChestEvents.ReleaseOrbs.OnClientEvent:Connect(function(pos)
	local TS = game:GetService('TweenService')
	local player = game.Players.LocalPlayer
	local Orb2 = script:WaitForChild("CoinOrb")
	local Orb = Orb2:Clone()
end)

Sometimes objects don’t load into the game right away. You could use WaitForChild to wait until the game detects that the object has loaded.It will yield (pause) the script until it detects that the part is there, or if it doesn’t exist, you will get a warning message in the output.

image
Does not work

@NicoleSydor same error

then it perhaps does not exist check if the part is still there when u play

1 Like

Is the archivable property of “CoinOrb” set to true?

1 Like

It isn’t when I play it. But if I test in a base plate, the coin orb is in the script. If I test it in another game, the coin orb is not in the script when I play it. It it because of the code written in the new game?

most likely check anywhere in the code where u delete it or somethn

You have to put the part inside of the script in order for it to work.

Also, you could have easily made a mistake in your code. For example, destroying the object or setting the part to another value… script.CoinOrb = game.Workspace trying to set the part itself instead of it’s parent would destroy the object.