I can’t do that with the clickdetector and the tool.
The script should not be a localscript.
I’ve already read this through, I just don’t understand how to insert it!
Here is the code:
local Baum = script.Parent.Parent.Parent.Baum
local clickDetector = Baum.ClickDetector
local schlaege = 8
local debounce = true
local Toolname = "Wood Axe"
clickDetector.MouseClick:Connect(function(plr)
if plr and plr.Character and plr.Character:FindFirstChild(Toolname) then
if debounce == true then
print("Schwing!")
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
clickDetector.MaxActivationDistance = 0
Baum.CanCollide = false
debounce = false
wait(30)
Baum.Transparency = 0
Baum.Leaves1.Transparency = 0
Baum.Leaves2.Transparency = 0
schlaege = 8
clickDetector.MaxActivationDistance = 32
Baum.CanCollide = true
debounce = true
end
end
end
end)
Add a localscript into the tool with the code.
In the script detect if the Hit is a log.
If so, fire a RemoteEvent, and then from there connect to it from a serverscript.
Put a LocalScript inside the Tool, and in that script, use the Tool’s Activated connection to get when the player clicked using that tool. Then using LocalPlayer:GetMouse() you can get the mouse’s Target object that the player clicked on. Then if the target object was an object of the tree, then continue with your original tree cutting function.
Hey it Works with this Localscript in the Axe, Thanks for Dev_Ryan and majdTRM
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer -- from a LocalScript
local mouse = localPlayer:GetMouse()
local schlaege = 8
local debounce = true
local Baum = workspace.Baum
mouse.Button1Down:Connect(function()
if mouse.Target == Baum then
if debounce == true then
print("You hit me!")
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
wait(30)
Baum.Transparency = 0
Baum.Leaves1.Transparency = 0
Baum.Leaves2.Transparency = 0
schlaege = 8
Baum.CanCollide = true
debounce = true
end
end
end
end)
But I have 2 more problems now.
There are several trees and only the same one can be clicked, the others are ignored.
It works even if the ax is in the backpack. It should only work if the ax is equipped. I’ve already tried it.
local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.Parent = game.Players.LocalPlayer.Backpack
function onActivation()
print("Tool activated")
end
tool.Activated:Connect(onActivation)
Thank it Works. But,
There are several trees and only the same one can be clicked, the others are ignored.
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer -- from a LocalScript
local mouse = localPlayer:GetMouse()
local schlaege = 8
local debounce = true
local Baum = workspace.Baum
local Tool = script.Parent.Parent.WoodAxe
Tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if mouse.Target == Baum then
if debounce == true then
print("You hit me!")
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
wait(30)
Baum.Transparency = 0
Baum.Leaves1.Transparency = 0
Baum.Leaves2.Transparency = 0
schlaege = 8
Baum.CanCollide = true
debounce = true
end
end
end
end)
end)
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!
-- 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