Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago
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

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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.

0
Wow didn't know i needed all that, thanks, i see now what was wrong with the script i was making. Supergamerboy1995 129 — 8y
0
No problem. Pyrondon 2089 — 8y
Ad

Answer this question