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