How do you make it so a client script can detect a part that was created from serverScript?

I’m having issues with my client script not picking up on a part named “Bullet” that was replicated and parented to workspace by a serverscript and then passed onto the client as a objValue.

I tried just passing the part as a value and not wrapped in a objvalue, well that failed, so then I tried passing it as a object value and that also failed, the client never seems to recognize the part exists no matter what.

Server Script

game.ReplicatedStorage.ShotFired.OnServerEvent:Connect(function(player, mousePosition, Hull, Barrel)

	local bullet = game.ReplicatedStorage.Bullet:Clone()
	bullet.Parent = workspace
	bullet.CanCollide = false
	bullet.CFrame = Barrel.Attachment.WorldCFrame

	task.wait()
	bullet:SetNetworkOwner(player)
	
	game.Debris:AddItem(bullet, 10)
	local objvalue = Instance.new("ObjectValue")
	objvalue.Value = bullet
	
	game.ReplicatedStorage.ShotFired:FireClient(player, objvalue)
	
end)

Local Script

game.ReplicatedStorage.ShotFired.OnClientEvent:Connect(function(objValue)
	local bullet = objValue.Value
	bullet:ApplyImpulse(bullet.CFrame.LookVector * bullet.AssemblyMass * 500)
end)

The client needs to recognize that the object exists in the first place, the problem may just be that the part hasn’t replicated over.

Anyway, is there any reason you can’t create the part on all the clients instead of on the server? Wouldn’t that be more optimal?

I’m restricted to my limited knowledge of scripting

When a bullet is created, do the clients see the bullet? If so, the bullet itself is probably replicating from server to client.

I’m wondering if ShotFired can simply pass the bullet itself, instead of the ObjectValue. Might be simpler to just pass the bullet itself. That said, passing the ObjectValue might be less data to send over a network connection (the less data sent over the network, the better!). So there are pros and cons to both.

If the bullet is replicating from the server to the client, I suspect the problem may be that objvalue has no Parent. When an object is created, the Parent is nil, and that might mean the server-side part is not replicating to the client. Try setting the objvalue’s Parent to a ReplicatedStorage folder (ReplicatedStorage is visible to both clients and servers). :slightly_smiling_face: