Hello, I am trying to make a script detect when it was hit by a tool that is swinging/activated The tool changes a value called "active" to 1 when swinging and back to zero when done. That part seems to be working. There is a comment showing where the script does not run past, yet I do not get an error.
game:WaitForChild("Players")
local folder = script.Parent
local toolName = "realTool"
local currency = "DNA"
local start = true
local function collectitem(obj, otherpart)
print("we got here")
local player = game.Players:FindFirstChild(otherpart.Parent.Name)
print("here too")
if player == otherpart.Parent.Name then
print("wow") -- script doesnt go here, it just stops and I cant figure out why
if player.Character:FindFirstChild(toolName) then
print("got this far")
local amount = obj.Amount.Value
obj:Destroy()
player.leaderstats[currency].Value += amount
end
end
end
for _, obj in pairs(folder:GetChildren()) do
if obj:IsA("Model") and obj:FindFirstChild("hit") then
obj.hit.Touched:Connect(function(otherpart)
if otherpart.Parent.active.Value == 1 then
collectitem(obj, otherpart)
print("plant cut")
print(otherpart.Parent.active.Value)
else
print("plant not cut")
print(otherpart)
print(otherpart.Parent.active.Value)
end
end)
end
end

4 comments
Nope, that didnt work
Nevermind, that did work, otherpart:IsA("Tool") shouldve been otherpart.Parent:IsA("Tool"), thanks for your help.
oop lol, I just edited my question too because I made sure it worked in studio real quick
my answer*