Children are not being passed when there parent is passed through a RemoveEvent

I have parts that i’m cloning to create a explosion effect (on the client for performance)

the issue is that the children (textures) are not inside the part when its cloned even though the part it was cloned from has textures on the server

explosions module:

local module = {}
local blockservice = require(game.ServerScriptService.BlockService)
local Particles = require(game.ReplicatedStorage.Modules.Particles)
local renderExplosion = game.ReplicatedStorage.Events.RenderExplosion



function module:createExplosion(pos,range,FX)
		for i,block in pairs(blockservice:getNearby(pos,range)) do
			renderExplosion:FireAllClients(pos, block)
			blockservice:destroy(block.Position)
		end
	if FX then	
		Particles.create(FX,pos,Vector3.new(.1,.1,.1),.15)
	end
end

return module

local script:

local renderExplosion = game.ReplicatedStorage.Events.RenderExplosion

renderExplosion.OnClientEvent:Connect(function(pos, block)
	local block = block:Clone()
	block.Anchored = false
	block.CollisionGroup = "Effects"
	block.Parent = workspace.Effects
	local A0 = Instance.new("Attachment")
	local A1 = Instance.new("Attachment")
	A0.Parent = block
	A1.Parent = block
	A0.Position = Vector3.new(-2,2,2)
	A1.Position = Vector3.new(2,-2,-2)
	local trail = game.ReplicatedStorage.Particles.CometTrail:Clone()
	trail.Parent = block
	trail.Attachment0 = A0
	trail.Attachment1 = A1
	block:ApplyImpulseAtPosition((block.Position-pos),Vector3.new(1,1,1)*1000)
	task.delay(1,function()
		block:Destroy()
	end)
end)
6 Likes

Which one are you using: Windows or Mac? Ironically, both operating systems have completely unrelated bugs that can cause your issue. Double whammy.

2 Likes

Was that possible ? How Lol :sob::joy:

3 Likes

i’m using windows 10, so this isnt my fault?

2 Likes

At any rate no but with windows 10 im not sure. I know :clone has some odd things about it
Other thing remoteevents are held together to prevent lag. this is just an example to show what i mean, lets say you call a remote 5 times in a 10th of a second, they are called all at once later to prevent lag. so the event maybe not be called exactly when you want it to.

So the actual event may be called after you are doing the destroy function. which i would also like to see.

3 Likes

ok, ill test when the event is being ran vs when the part is destroyed, even then it should still have the children if its destroyed right?

2 Likes

No. When you call destroy on an instance, all of its children will also have destroy called on them. Destroy sets the parent of an instance to nil, meaning that the instance’s (and all of it’s children) parent will be set to nil.

2 Likes

ohhhh okay that makes sense, and the parts are being destroyed before the event…
how would i make sure the event is fired before the destroy?
image

1 Like

It doesnt matter bc it will still work. But you can do a remotefunction and wait for it to return and then destroy the block after it returns anything

1 Like

I don’t believe there is a way to do so, as instantaneous server-client communication is impossible and RemoteEvents do not yield. An idea that comes to mind is to also pass the instance’s children as a parameter, iterate through them on the client, and clone and parent them to the part as well:

Explosions Module:

function module:createExplosion(pos,range,FX)
		for i,block in pairs(blockservice:getNearby(pos,range)) do
			renderExplosion:FireAllClients(pos, block, block:GetChildren())
			blockservice:destroy(block.Position)
		end
	if FX then	
		Particles.create(FX,pos,Vector3.new(.1,.1,.1),.15)
	end
end

Local script:

local renderExplosion = game.ReplicatedStorage.Events.RenderExplosion

renderExplosion.OnClientEvent:Connect(function(pos, block, children)
	local block = block:Clone()
	for _,v in (children) do
		v:Clone().Parent = block
	end
    -- Rest of code
end)

This approach would probably be the least time consuming but I’m not entirely sure if it’s that optimal either. :person_shrugging:

3 Likes

Shouldn’t they just store the block on ReplicatedStorage? And just send the name of the block to the client, and the client can just fetch and clone it?

1 Like

I don’t know OP’s situation but with the code that they provided, I assumed that blockservice:getNearby() returned an array of BaseParts located inside of workspace that are within the specified range relative to the position they pass through it. They would have to insert every different type of part inside of ReplicatedStorage if that was the case — which in the event they have a fully fledged map, would be very time consuming.

4 Likes

it runs through every part in a folder in workspace and checks if its in the range relative to the position,

here was my solution:

i added this to the start of the task.spawn thread in the local script

local block = block:Clone()
for i,child in children do
	if child:IsA("Texture") then
		local c = child:Clone()
		c.Parent = block
	end
end

and in the module added a children parameter

renderExplosion:FireAllClients(pos, block,block:GetChildren())

I also replaced the RemoteEvent with an UnreliableRemoteEvent

2 Likes

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