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

How do I respawn an object when it fell into the void?

Asked by
MattVSNNL 620 Moderation Voter
4 years ago
Edited 4 years ago

I'm making a game where you insult the tree and it will grow and I got this problem where it grows too big and it will fall into the void so how do I respawn it?

1 answer

Log in to vote
0
Answered by 4 years ago

I think you could do something like this

local ReplicatedStorage = game:GetService("Replicated Storage")
local SaveTree = ReplicatedStorage.Tree -- Put your tree in replicated storage so you can copy it from there later
local RunService = game:GetService("RunService") -- Doing this so you can check every frame for the tree dissapearing
local function respawnTree()
    if game.Workspace.Tree then -----Change this part to be able to find the tree when the game starts
        wait()
    else
        local Tree = SaveTree:Clone()
        Tree.Parent = game.Workspace ------Change this too if you are changing the place to find the tree above
        Tree.Name = "Tree"
        Tree.Position = Vector3.new( -- Put in the place you want the tree to go to when it despawns and when is is first put into the world. If you want it to respawn in a different place than where is originally spawns then you need to put the tree where you want it to be when the game starts then type in the coordinates that you want it to respawn in here. If you will do the second option, you will have to change the place where the code can find the tree)
    end
end

RunService.Heartbeat:Connect(function()
    respawnTree
end)

Sorry if I was a bit confusing with this

0
I can't put it in replicated storage because then the tree script where it grows from hate words will go and thats the point of the game MattVSNNL 620 — 4y
0
I'm confused, what do you mean? Longjohnnn 28 — 4y
Ad

Answer this question