[SOLVED] Need Help for Wood Cutting Script!

Sry, but this is too difficult for me.

Is there maybe another solution?

Or would someone be so nice for me and do that with three trees so that I can see the code?
I can just upload what I have!

Sorry i didnt see your posts.

Why cants you just check if the name of the target is “Baum”?

mouse.Target.Name =="Baum"

That doesn’t work, I take down a tree and another shows the result.

Can you do this for me, please? I don’t get this with the (See CollectionService (roblox.com) and Tag Editor - Roblox) this is too hard for me! i dont understand it!

Okay, the reason it is affecting another tree, is because you are changing the properties of a avariable you already set.

Simply add this before if mouse.Target.Name == "Baum":

local Baum = mouse.target

Then show me your code.


For the second part, CollectionService helps you add tags to objects.

For example:

local CollectionService = game:GetService("CollectionService")

if CollectionService:HasTag(part, "Some Tag") then
  -- do somethig here
end

Basically, it checks if part has the tag “Some Tag”.

You can use
Tag Plugin to add these tags in studio, and check them with your script.

But it is not necessary

Hey, thanks for your Help. Is that right?

I have installed “Tag Editor” and is that right?
2

-- test
local CollectionService = game:GetService("CollectionService")
-- test
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer -- from a LocalScript
local mouse = localPlayer:GetMouse()
local schlaege = 8
local debounce = true
local Baum = mouse.target
local Tool = script.Parent.Parent.WoodAxe
-- test
if CollectionService:HasTag(Baum, "Some Tag") then
-- test
Tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if mouse.Target == "Baum" then
			if debounce == true then
				print("Du schlägst Baum!")
				schlaege = schlaege - 1
				if schlaege == 6 then
					Baum.Leaves2.Transparency = 1
				end
				if schlaege == 3 then
					Baum.Leaves1.Transparency = 1
				end
				if schlaege == 0 then
					Baum.Transparency = 1
					Baum.CanCollide = false
					debounce = false
					mouse.Target.respawn.Value = true
					print("Der Baum fällt!")

					wait(5)
					Baum.Transparency = 0
					Baum.Leaves1.Transparency = 0
					Baum.Leaves2.Transparency = 0	
					schlaege = 8	
					Baum.CanCollide = true	
					debounce = true	
				end
			end			
		end
	end)
	end)
end

It doesn’t work.

I’ll send you the rxbl
NewTreeHitSystem.rbxl (71,5 KB)

Ah, you need to detect if mouse.Target has tag, not “Baum”. In fact, you should not use the variable Baum. Simply delete it.

This is what I meant:

Tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if CollectionService:HasTag(mouse.Target, "Some Tag") then
			local Baum = mouse.Target
			if debounce == true then
				print("Du schlägst Baum!")
				schlaege = schlaege - 1
				if schlaege == 6 then
					Baum.Leaves2.Transparency = 1
				end
				if schlaege == 3 then
					Baum.Leaves1.Transparency = 1
				end
				if schlaege == 0 then
					Baum.Transparency = 1
					Baum.CanCollide = false
					debounce = false
					mouse.Target.respawn.Value = true
					print("Der Baum fällt!")

					wait(5)
					Baum.Transparency = 0
					Baum.Leaves1.Transparency = 0
					Baum.Leaves2.Transparency = 0	
					schlaege = 8	
					Baum.CanCollide = true	
					debounce = true	
				end
			end			
		end
	end)
end)
1 Like

Hey, thank you. It Works Perfekt.

one more question. I have now set the tree to respawn for 30 seconds. In that time I cannot cut down another tree. How can I best solve this?

I saw the problem, I can’t solve it.

I’ve tried Touchevent to respawn the tree, but you can’t control a server script with a local script.

My next attempt: Sending the variable respawn to the script via localscript with events does not work.

Next try:
Send the mouse.target and mouse.Button1Down to the server. Does not work too.

Can’t get any further!

I think I solved it with Remote Event, if it works I’ll tell you!

It dosn´t work !
All trees are deleted because each tree has the same remote event. I tried “If Baum.respawn.Value == true” but it doesn’t respond.

LocalScript

local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer -- from a LocalScript
local mouse = localPlayer:GetMouse()
local schlaege = 8
local debounce = true
local Tool = script.Parent.Parent.WoodAxe

--test
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
--test


Tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if CollectionService:HasTag(mouse.Target, "Some Tag") then
			local Baum = mouse.Target
			if debounce == true then
				print("Du schlägst Baum!")
				schlaege = schlaege - 1
				if schlaege == 6 then
					Baum.Leaves2.Transparency = 1
				end
				if schlaege == 3 then
					Baum.Leaves1.Transparency = 1
				end
				if schlaege == 0 then
					Baum.Transparency = 1
					Baum.CanCollide = false
					debounce = false
					Baum.respawn.Value = true
					print("Der Baum fällt!")
					--test
					remoteEvent:FireServer()
					--test
					
				--	wait(10)
				--	Baum.Transparency = 0
				--	Baum.Leaves1.Transparency = 0.02
				--	Baum.Leaves2.Transparency = 0.02	
					schlaege = 8	
				--	Baum.CanCollide = true	
					debounce = true	
				end
			end			
		end
	end)
end)

Script in the Tree

local Baum = script.Parent.Parent.Baum
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

local function testpart ()
	if Baum.respawn.Value == true then
		
	
	Baum.Transparency = 1
	Baum.Leaves2.Transparency = 1
	Baum.Leaves1.Transparency = 1
	Baum.CanCollide = false
	wait(10)
	Baum.Transparency = 0
	Baum.Leaves1.Transparency = 0.02
	Baum.Leaves2.Transparency = 0.02		
		Baum.CanCollide = true
		Baum.respawn.Value = false
	end
end

remoteEvent.OnServerEvent:Connect(testpart)

The problem here is that when you set “Baum.Respawn” from the localscript, it does not sync to the other side.

You can instead pass true to FireServer and add an argument to “testpart”

e.g.

LocalScript

remoteEvent:FireServer(true)

Server Script

local function testpart (respawn)
	if respawn then
		Baum.Transparency = 1
		Baum.Leaves2.Transparency = 1
		Baum.Leaves1.Transparency = 1
		Baum.CanCollide = false
		wait(10)
		Baum.Transparency = 0
		Baum.Leaves1.Transparency = 0.02
		Baum.Leaves2.Transparency = 0.02		
		Baum.CanCollide = true
		Baum.respawn.Value = false
	end
end

Also, make sure to change leaf transparency on the server, not from the localscript!

Yes, exactly. All players should see that the tree is gone.

But that doesn’t work because the ClickDetector doesn’t work with tool.

Then, as you have been doing, fire a remoteevent, and make the tree disappear from the regular script. From there, also add points to the player and everything else.

try using a tool equip event like where the tool is equipped and you will be able to cut down the tree.

I understand what you mean, but I won’t make it with my little experience.
Do you have an example?

The script works, only when I cut a tree they all disappear.

Please don’t get me wrong, I want to learn that. But at some point I don’t know what to do next.