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

Is it possible to make my tree in roblox regenerate after breaking?

Asked by 4 years ago
Edited 4 years ago

OK for the first script ( localscript ) it is in Starterpack. The I set the time to 2 for testing it out faster and the tree still wont regenerate.

repeat wait() until game.Players.LocalPlayer.Character
local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Mouse = Plr:GetMouse()
local CouldGetWood = true
local TreeCutDown = false
local Treee = game.Workspace.Tree

function ShowProgress(tree)
 if tree == "Tree" then
  for i = 0,1,.01 do
   WC.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
   wait()
  end
 elseif tree == "HardTree" then
  for i = 0,1,.005 do
   WC.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
   wait()
  end
 end
end

Mouse.Button1Down:connect(function()
 if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "Tree" and CouldGetWood == true then
  local Wood = Mouse.Target
  if (Wood.Position - Char.UpperTorso.Position).magnitude < 10 then
   CouldGetWood = false
   WC = Plr.PlayerGui.WoodChopper
   WC.BG.Visible = true
   Char.Humanoid.WalkSpeed = 0
   ShowProgress ("Tree")
   Char.Humanoid.WalkSpeed = 16
   for i,v in pairs(Wood.Parent.Leaves:GetChildren())do
    if v:IsA("Part") then
     v.Anchored = false
    end
   end
   Wood:Destroy()
   WC.BG.Visible = false
   TreeCutDown = true
   CouldGetWood = true
  end
 end

 if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "HardTree" and CouldGetWood == true then
  local Wood = Mouse.Target
  if (Wood.Position - Char.Torso.Position).magnitude < 10 then
   CouldGetWood= false
   WC = Plr.PlayerGui.WoodChopper
   WC.BG.Visible = true
   Char.Humanoid.WalkSpeed = 0
   ShowProgress ("HardTree")
   Char.Humanoid.WalkSpeed = 16
   for i,v in pairs(Wood.Parent.Leaves:GetChildren())do
    if v:IsA("Part") then
     v.Anchored = false
    end
   end
   Wood:Destroy()
   TreeCutDown = true
   WC.BG.Visible = false
   CouldGetWood = true
  end
 end
end)

while wait(2) and TreeCutDown == true do --Runs every 60 seconds and checks if the trees were cut down                                                                 
    game.ReplicatedStorage.TreeSpawner:FireServer(Treee, "Name", Vector3.new(505, 30.546, 90.298), game.Workspace.Tree)--Change the game.Workspace.TreesModel to whatever you want, just make sure its in the workspace
    TreeCutDown = false
end

Now for the second script that is also in Starter pack but it is a regular script ( not localscript ) I'm getting this error for that script, 14:44:57.830 - TreeSpawner is not a valid member of ReplicatedStorage, I dont know if this error affects the first script of the respawning. Here is the second script.

game.ReplicatedStorage.TreeSpawner.OnServerEvent:Connect(function(Player, Object,name, Position, Place)

    local Tree = Object:Clone() --Clones the tree
    Tree.Name = name
    Tree.Parent  = Place 
    Tree.Position = Vector3.new(Position)
end)
0
change Treee on line 68 to game.Workspace.Tree and change Wood on line 68 also to Treee mixgingengerina10 223 — 4y
0
I told you to add a remote event in replicated storage named TreeSpawner mixgingengerina10 223 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

First we need to make a variable to check if the tree has been cut down to prevent multiple trees at the same place: Also make sure to go to ReplicatedStorage and add a "RemoteEvent" and name it TreeSpawner

repeat wait() until game.Players.LocalPlayer.Character
local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Mouse = Plr:GetMouse()
local CouldGetWood = true
local TreeCutDown = false --Is the tree cut down?

function ShowProgress(tree)
 if tree == "Tree" then
  for i = 0,1,.01 do
   WC.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
   wait()
  end
 elseif tree == "HardTree" then
  for i = 0,1,.005 do
   WC.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
   wait()
  end
 end
end

Mouse.Button1Down:connect(function()
 if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "Tree" and CouldGetWood == true then
  local Wood = Mouse.Target
  if (Wood.Position - Char.UpperTorso.Position).magnitude < 10 then
   CouldGetWood = false
   WC = Plr.PlayerGui.WoodChopper
   WC.BG.Visible = true
   Char.Humanoid.WalkSpeed = 0
   ShowProgress ("Tree")
   Char.Humanoid.WalkSpeed = 16
   for i,v in pairs(Wood.Parent.Leaves:GetChildren())do
    if v:IsA("Part") then
     v.Anchored = false
    end
   end
   Wood:Destroy()
   WC.BG.Visible = false
   TreeCutDown = true --The tree was cut down and set the value to true
   CouldGetWood = true
  end
 end

 if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "HardTree" and CouldGetWood == true then
  local Wood = Mouse.Target
  if (Wood.Position - Char.Torso.Position).magnitude < 10 then
   CouldGetWood= false
   WC = Plr.PlayerGui.WoodChopper
   WC.BG.Visible = true
   Char.Humanoid.WalkSpeed = 0
   ShowProgress ("HardTree")
   Char.Humanoid.WalkSpeed = 16
   for i,v in pairs(Wood.Parent.Leaves:GetChildren())do
    if v:IsA("Part") then
     v.Anchored = false
    end
   end
   Wood:Destroy()
   TreeCutDown = true--The tree was cut down and set the value to true
   WC.BG.Visible = false
   CouldGetWood = true 
  end
 end
end)

After that we will make a while loop that'll check if the tree was cut down..

repeat wait() until game.Players.LocalPlayer.Character
local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Mouse = Plr:GetMouse()
local CouldGetWood = true
local TreeCutDown = false

function ShowProgress(tree)
 if tree == "Tree" then
  for i = 0,1,.01 do
   WC.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
   wait()
  end
 elseif tree == "HardTree" then
  for i = 0,1,.005 do
   WC.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
   wait()
  end
 end
end

Mouse.Button1Down:connect(function()
 if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "Tree" and CouldGetWood == true then
  local Wood = Mouse.Target
  if (Wood.Position - Char.UpperTorso.Position).magnitude < 10 then
   CouldGetWood = false
   WC = Plr.PlayerGui.WoodChopper
   WC.BG.Visible = true
   Char.Humanoid.WalkSpeed = 0
   ShowProgress ("Tree")
   Char.Humanoid.WalkSpeed = 16
   for i,v in pairs(Wood.Parent.Leaves:GetChildren())do
    if v:IsA("Part") then
     v.Anchored = false
    end
   end
   Wood:Destroy()
   WC.BG.Visible = false
   TreeCutDown = true
   CouldGetWood = true
  end
 end

 if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "HardTree" and CouldGetWood == true then
  local Wood = Mouse.Target
  if (Wood.Position - Char.Torso.Position).magnitude < 10 then
   CouldGetWood= false
   WC = Plr.PlayerGui.WoodChopper
   WC.BG.Visible = true
   Char.Humanoid.WalkSpeed = 0
   ShowProgress ("HardTree")
   Char.Humanoid.WalkSpeed = 16
   for i,v in pairs(Wood.Parent.Leaves:GetChildren())do
    if v:IsA("Part") then
     v.Anchored = false
    end
   end
   Wood:Destroy()
   TreeCutDown = true
   WC.BG.Visible = false
   CouldGetWood = true
  end
 end
end)

while wait(60) and TreeCutDown == true do --Runs every 60 seconds and checks if the trees were cut down                                                                 
    game.ReplicatedStorage.TreeSpawner:FireServer(Wood, "Name", Vector3.new(Position), game.Workspace.TreesModel)--Change the game.Workspace.TreesModel to whatever you want, just make sure its in the workspace
    TreeCutDown = false
end

and in another script, make sure its a SERVER SCRIPT, the scripts that are blue colored

game.ReplicatedStorage.TreeSpawner.OnServerEvent:Connect(function(Player, Object,name, Position, Place)

    local Tree = Object:Clone() --Clones the tree
    Tree.Name = name
    Tree.Parent  = Place 
    Tree.Position = Vector3.new(Position)
end)
0
Ok this is good, but im a noob at some things... maybe. So whats workspace hierarchy and how do I get the position I want? Thanks for the help MrMeeper9 39 — 4y
0
See the explorer in the right hand side? There is an object named Workspace, choose in which model or part in the workspace you want the tree to respawn; You can get the position by click on the tree, going down to the properties and find its position, you can copy and paste it in the place I told you to. I'll also update the script since it doesn't clone the tree globally. mixgingengerina10 223 — 4y
0
Ok, I updated it, make sure to reread the answer. :D mixgingengerina10 223 — 4y
0
Ok so one last problem. First I put that new bottom script into a regular script, not localscript. I made a variable named tree. Here is the thing for that, local Treee = game.Workspace.Tree . And I pasted that where you wanted. Wood and position are unknown global's and are underlined in blue. I will post the whole script in my post. MrMeeper9 39 — 4y
View all comments (8 more)
0
Replace wood with tree variable, position, is the position you want the tree to spawn, you can get it by clicking on the tree, looking in its properties, and copy and pasting its position mixgingengerina10 223 — 4y
0
Ok ima go over every thing in my original post MrMeeper9 39 — 4y
0
I told you to add a remote event in the replicated storage named TreeSpawner :/ mixgingengerina10 223 — 4y
0
Update, so no errors are running. There is a remote event now in replicated storage named "TreeSpawner". Sorry, my eyes completely missed the remote event part, idk why I reread alot. Now as I said no errors, but they tree wont regenerate. Aswell as I tested it with friends and when I break a tree it doesnt break on their part which I dont mind everyone having their own trees on their part. MrMeeper9 39 — 4y
0
Do you have discord? mixgingengerina10 223 — 4y
0
Yes MrMeeper9 39 — 4y
0
Can you tell me your discord? mixgingengerina10 223 — 4y
0
Yan #2066 MrMeeper9 39 — 4y
Ad

Answer this question