Waiting for a Clone()ed part to load

code

local CloneBall = game.ReplicatedStorage.Ball:Clone()
CloneBall.Parent = game.Workspace
CloneBall.Position = SpecificArm.RayGun.Position
CloneBall.Anchored = false
--send it
CloneBall.AssemblyLinearVelocity = (MousePos3D - SpecificArm.Position).Unit * Velocity * 10
	
	
--ball is running, now focus the camera on the ball:
game.ReplicatedStorage.CopyFireGun.ClientTrackBallAll:FireAllClients(CloneBall)

problem:
When I activate the remoteEvent it reads nil. When I do a wait(1) it doesn’t. How do I know when the part is fully loaded in? This is on the server.

Try this code:

local success, errorMessage = pcall(function()
task.wait()

local CloneBall = game:GetService("ReplicatedStorage"):WaitForChild("Ball"):Clone()
CloneBall.Parent = game.Workspace
CloneBall.Position = SpecificArm.RayGun.Position
CloneBall.Anchored = false
--send it
CloneBall.AssemblyLinearVelocity = (MousePos3D - SpecificArm.Position).Unit * Velocity * 10
	

game:GetService("ReplicatedStorage"):WaitForChild("CopyFireGun"):WaitForChild("ClientTrackBallAll"):FireAllClients(CloneBall)
end

if not success then
warn(errorMessage)
end

I used pcall() to print the errors

Also, it’s better you put the ball in ServerStorage. Because in Server, its Storage is ServerStorage. And in Local, its Storage, is ReplicatedStorage.

1 Like

Try something like this;

local ContentProviderService = game:GetService('ContentProvider')
local CloneBall = game.ReplicatedStorage.Ball:Clone()
CloneBall.Parent = workspace
ContentProviderService:PreloadAsync({Cloneball}) --This yields until it's loaded
CloneBall.Position = SpecificArm.RayGun.Position
CloneBall.Anchored = false
--send it
CloneBall.AssemblyLinearVelocity = (MousePos3D - SpecificArm.Position).Unit * Velocity * 10
	
	
--ball is running, now focus the camera on the ball:
game.ReplicatedStorage.CopyFireGun.ClientTrackBallAll:FireAllClients(CloneBall)

It may not work, but KarilbolCoolCold is right, you should use ServerStorage if the client doesn’t need access to the original Ball that’s being cloned.

2 Likes

That’s a pretty smart idea!

Well but at least your idea was good. You’re right, it can be from not loading the content right.

2 Likes

Nope, doesn’t work. Interesting idea though

I think it might be easier not using remote events for this, but instead, have each client listen to child added on the workspace, and then having them verify that the ball was the instance that just got added.

1 Like

I tried it without the pcalls, but it still doesn’t work.

I am going to use this as a last resort. There’s gotta be someway to tell when a part has fully loaded.

Try to put the ball in ServerStorage instead (and change the script “Replicated Storage” to “ServerStorage” ofc)


Video of whats happening
Edit: It kind of pauses mid air, if it was perfect it’d get unanchored right away.

It’s better practice to have the client listen on the ChildAdded event for cases like these since it’ll work 100% of the time. Right now, the code you’re running is simply acting like a wrapper for the ChildAdded event, except for the fact that you’re now having to deal with the race condition of the server replicating the ball to the client.

2 Likes

code used incase anyone is wondering:

local Player = game:GetService("Players").LocalPlayer
local Ball

game.Workspace.ChildAdded:Connect(function(instance)
	if instance.Name == "Ball" then
		
		Ball = instance
		CurrentCamera.CameraType = Enum.CameraType.Track
		CurrentCamera.CameraSubject = Ball
		Player.CameraMaxZoomDistance = 100
		Player.CameraMinZoomDistance = 100
		
	end
end)
1 Like

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