Hello, I am a sort of beginner scripter. I need help with this program I am making for an axe and tree system in one of my first projects. I want it so the tree only says it has been hit when you are equipped with an axe, and if you hit the tree holding anything else or anything at all then the axe ignores the input. Heres my code below, there is no error messages just there isn’t anything being printed at all.
local ClickDetector = script.Parent
local Plr = game.Players.LocalPlayer
local Axe = Plr.Backpack:FindFirstChild("Axe") or Plr.Character:FindFirstChild("Axe")
local AxeEquipped = false
ClickDetector.MouseClick:Connect(function(Player)
if AxeEquipped == true then
print("(hit " .. tostring(script.Parent.Name) .. ")")
else
print("No axe found, cancelled hit.")
end
end)
if Plr.Character:FindFirstChildOfClass("Tool") then
AxeEquipped = true
else
AxeEquipped = false
end
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local Mouse = plr:GetMouse()
local Axe = plr.Backpack:FindFirstChild("Axe") or plr.Character:FindFirstChild("Axe")
local AxeEquipped = false
local Tree = game.Workspace.Tree
Mouse.MouseClick:Connect(function(plr)
if Axe.Equipped == true then
if Mouse.Target == Tree then
print("(hit " .. tostring(script.Parent.Name) .. ")")
else
print("No axe found, cancelled hit.")
end
end
end)
Axe.Equipped:Connect(function()
AxeEquipped = true
end)
Axe.Unequipped:Connect(function()
AxeEquipped = false
end)
No errors, click icon appears when hovering over the tree but no code is printed when I click the tree, help.
local Players = game:GetService("Players")
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local Axe = plr.Backpack:FindFirstChild("Axe") or plr.Character:FindFirstChild("Axe")
local AxeEquipped = false
local Tree = game.Workspace.Tree
local t = Mouse.Target
local ClickDetector = script.Parent
Axe.ManualActivationOnly = true
ClickDetector.MouseClick:Connect(function(plr)
if Axe:Activate() then
if t == Tree then
print("(hit " .. tostring(script.Parent.Name) .. ")")
else
print("No axe found, cancelled hit.")
end
end
end)
Axe.Equipped:Connect(function()
AxeEquipped = true
end)
Axe.Unequipped:Connect(function()
AxeEquipped = false
end)
Honestly, I thought this would be a lot easier than it has been and I am starting to get really confused with some of these concepts, so I don’t really know how to go from here without just getting someone to do it for me. I tried using the “Tool.ManualActivationOnly” property but I am quite tired and don’t really understand what it truly means, I want to get this done tonight though so I don’t really want to rest on it, could you apply this to my code if possible or give me a helping hand on where exactly to apply it?
Also, its started showing a click detector icon when I don’t have the tool equipped which I don’t want, I think this is cause as previously stated ClickDetectors and tools really don’t like each other?
You could try placing a proximity prompt inside the tree, and when the prompt gets clicked, you can detect if the player is holding an axe and do stuff from there.
And you might want to elaborate more on pretty much everything, like, where is the script located or is the script a Local or Server script. Because from what I could tell, the script you’re using is a regular script that’s located in the tree, but then there’s code like plr:GetMouse() which only work in local scripts and Axe.Equipped:Connect(function() which contradicts the script being inside of the tree, and after rereading like 10 times, the script seems to be a local script that’s located inside the axe, the complete opposite of what I was thinking, but even then, there’s script like ClickDetector.MouseClick:Connect(function(Player) which 1, the click detector is assumed to be on the tree, again, contradicting the where the script is, 2, don’t do local scripts with click detector, if you want it to do something for 1 person to see, use a remote event for that, and 3, there’s no 3, I just like having the 3rd option.
In all honestly, that script is just a skrew up, just delete it and start a new script, and I guess do what I said from above.
Sorry if this sounded rude but if you want proper help, you should give us the proper details.
local PPS = game:GetService("ProximityPromptService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local function ToolEquipped(prompt)
local tool = player.Character:FindFirstChildWhichIsA("Axe")
if tool ~= nil then
prompt.Enabled = true
end
end
local function CheckPrompt(prompt)
if prompt.Name == "ProxPrompt" then
if player.Character:FindFirstChildWhichIsA("Axe") ~= nil then
print("(hit " .. tostring(script.Parent.Parent.Name) .. ")")
prompt.Enabled = true
else
prompt.Enabled = false
player.Character.ChildAdded:Connect(function()
ToolEquipped(prompt)
end)
end
end
end
PPS.PromptShown:Connect(CheckPrompt)
However, when I go near the prompt I see it for a very blank second and it instantly disappears, (clearly the code is written accidentally to hide the prompt half way through)