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.
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.
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.
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.
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.
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)