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

Cant get an object to go away after on touch and respawn where it started from, help?

print("LandMine Script Loaded")

LandMine = script.Parent

function onTouched(hit)
  explosion = Instance.new("Explosion")
  explosion.BlastRadius = 20
  explosion.BlastPressure = 100000
  explosion.Position = script.Parent.Position
  explosion.Parent = game.Workspace
  script.Parent.Transparency = 0
wait(2)
game.Workspace.Meteor.Meteor1:Destroy()
end

connection = LandMine.Touched:connect(onTouched)

This is the code i used to make the Meteor fall, hit the ground, and in 2 seconds go away. My only problem is that it gets destroyed, aka deleted from the game. Im trying to make it so that it goes away, and in 10 seconds respawns where it started from.

1 answer

✓ Accepted answer

You need to save its original position, and set its position back to that after setting the meteor's parent to nil (or wherever you want to put it while it waits to respawn).

print("LandMine Script Loaded")

local LandMine = script.Parent
local pos = game.Workspace.Meteor.Meteor1.Position
local meteor = game.Workspace.Meteor.Meteor1

function onTouched(hit)
  explosion = Instance.new("Explosion")
  explosion.BlastRadius = 20
  explosion.BlastPressure = 100000
  explosion.Position = script.Parent.Position
  explosion.Parent = game.Workspace
  script.Parent.Transparency = 0
  wait(2)
  meteor.Parent = nil
  wait(10)
  meteor.Parent = workspace
  meteor.CFrame = CFrame.new(pos) --// Edit this to fit your needs, e.g. if it's a model use :SetPrimaryPartCFrame() instead.
end

connection = LandMine.Touched:connect(onTouched)

Alternatively, you could set up a script that just destroys it and clones in a new one; it's up to you. Hope this helped.

2 comments

0

Wow didn't know i needed all that, thanks, i see now what was wrong with the script i was making.

0

No problem.

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