Hey, this is in the correct folder?

Hey devs,

So, something really strange happened to me. This is the error in the output I got:

S1 is not a valid member of Folder "Workspace.Shutters"  -  Client - ShuttersClose:5

image yes it is?

This is the code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.ShutterClosing

local TweenService = game:GetService("TweenService")
local shutter1 = game.Workspace.Shutters.S1

local goal1 = {}
goal1.Position = Vector3.new(272.983, 6.7, -446.525)

local tweenInfo = TweenInfo.new(3)

local close1 = TweenService:Create(shutter1, tweenInfo, goal1)

RemoteEvent.OnClientEvent:Connect(function()
	close1:Play()
	shutter1.Closing:Play()
end)

:heart:

When you join the game the asset is probably/most likely hasn’t loaded in yet.

local shutter1 = game.Workspace:FindFirstChild("Shutters"):FindFirstChild("S1")
1 Like

If you’re running your script (which is Client script I suppose) at the start of the game, then S1 might still not exist because it’s not replicated from server yet, try using game.Workspace:WaitForChild("Shutters"):WaitForChild("S1").

2 Likes

@StraightScared @Cloudy71 It worked but, now there is another issue:

TweenService:Create failed because Instance is null  -  Client - ShuttersClose:12

Shutter probably still hasn’t loaded in, if you want to fully know if the shutter loads than at the top of the script do

repeat task.wait() until game.Workspace:FindFirstChild("Shutters"):FindFirstChild("S1")
1 Like
local shutter1 = repeat task.wait() until game.Workspace:FindFirstChild("Shutters"):FindFirstChild("S1")

?

It has an error:

image

repeat task.wait() until game.Workspace:FindFirstChild("Shutters"):FindFirstChild("S1")

This should be on its own line at the top of the script, nothing else added on, its saying that this expression is wrong because you have

local shutter1 =

at the start of it.

1 Like

What do I do? Can you give me a sample of code? Ah, I figured it out. Thank you!

I’m pretty sure WaitForChild should work, using task.wait() is very bad approach to this situation.
WaitForChild basically does the same, but is more secure in case of yielding current thread.

That’s right, repeat task.wait() until instance:FindFirstChild() is not good.

The error is being thrown due to how replication works with instance streaming. @TeamDreams123 it might not be a bad idea to disable Streaming for now until you learn more about turning its benefits in your favour. (documentation) You should have no issues with what you have with no streaming.

Otherwise, adding to what Cloudy71 said, using WaitForChild() alone can still cause issues if the “shutter” is outside of the replication radius and doesn’t stream in. Using the timeout parameter of we can prevent the infinite yield and decide what to do if there is no “shutter” at the time.

This is just an example:

-- S1 will be found if it is a persistent model or if it is
-- in the replication radius
local shutters = workspace:WaitForChild("Shutters")
local S1 = shutters:WaitForChild("S1", 5)

if S1 then
	-- Safe to create tweens
else
	-- (S1 wasn't found, rely on signals to know
	-- when it streamed in, like CollectionService:GetInstanceAddedSignal())
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.