[SOLVED] Need Help for Wood Cutting Script!

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.

I think you and majdTRM are figuring out your solution, but I have an idea:

Use a remote event that triggers then quickly disables the hitbox of the axe on the server, and it damages the tree, this is what I did for my melee kit, and it works perfectly!

Sure.

In your tree script you can put:

local Baum = script.Parent
local remoteEvent = Baum.CutDown

local function testpart (respawn)
	if respawn 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
			Baum.respawn.Value = true
			print("Der Baum fällt!")

			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
		end
	end
end

remoteEvent.OnServerEvent:Connect(testpart)

And in the localscript you can keep:

Tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if CollectionService:HasTag(mouse.Target, "Some Tag") then
			local Baum = mouse.Target
			Baum.CutDown:FireServer()
		end
	end)
end)

But the tree script must be the child of the tree, and the RemoteEvent must be called CutDown

1 Like

Hey, I don’t know how to say it.

Many thanks to you. Everything works.

If I have a few more questions, can I write to you privately?

Sure, if you have any inquires, contact me at any time.

Try the Game. The Script is inside:

You didn’t accept me and I can’t write to you!?!