Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I clone something from Lighting when a certain object from Workspace is removed?

I tried to clone a Soccer ball from Lighting to Workspace when the ball gets deleted but it dosen't work.

wait(3) if game.Workspace.SoccerBall==nil then

local newball = game.Lighting.Ball:Clone() newball.Parent = game.Workspace newball.Position = Vector3.new(41.701, 7.071, 626.308) end

2 answers

✓ Accepted answer

Scubadoo2's answer is correct and takes the direction you initially suggested.


There's another option, which uses the ChildRemoved event:

function MakeNewBall()
	local newball = game.Lighting.Ball:Clone() 
	newball.Parent ...
	...
end

game.Workspace.ChildRemoved:connect( function(obj)
	if obj.Name == "SoccerBall" then
		MakeNewBall()
	end
end)

Whenever any object is removed from the workspace, we check if it was called "SoccerBall". In that case, we make the new one.

The reason why it isn't working is because... well... soccerball doesn't exist when it is removed, so it is trying to access something that isn't there. it will throw the error without seeing that it is checking for something.

To fix this, there is a command called :FindFirstChild that will return nil if it doesn't exist. so you may want to do wait(3) if game.Workspace:FindFirstChild("SoccerBall")==nil then.

This discussion is preserved as it was. New answers, comments, and votes are closed.