I want the handle.parent to check when it is touched but touched is not a valid meber of it
local handle = script.Parent
local Players = game:GetService("Players")
local goi = Players.LocalPlayer.PlayerGui.Gui
local Tween = game:GetService("TweenService")
local Replicatedstorage = game:GetService("ReplicatedStorage")
local Woodadd = Replicatedstorage.Wood
local woodPosition = UDim2.new(0.253, 0,-0.028, 0)
local tweenInfo = TweenInfo.new(2)
local leaderstats = Players.LocalPlayer:WaitForChild("leaderstats")
local wood = leaderstats.Wood
local damage = 20
local canSwing = true
db = true
dbbb = true
handle.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Tree"and db == true and not canSwing and hit.Parent.Canbeattacked.Value == false then
local amount
if goi:FindFirstChildOfClass("IntValue") then -- since you parent your int value to the goi thing I checked that
else
amount = Instance.new("IntValue")
amount.Parent = goi
end
amount = goi:FindFirstChildOfClass("IntValue")
local tree = hit.Parent
local modelCFrame = tree:GetPivot()
local health = tree.Health
local DamageDelt = tree.DamageDelt
db = false
local oldpos = tree.Tree.CFrame.Position
local goal = {CFrame = script.Parent.CFrame * (CFrame.new(1,1,1) * CFrame.Angles(math.rad(75),0,0))}
local tweenlog = Tween:Create(tree.Tree,tweenInfo,goal)
goi.CanvasGroup.Visible = true
health.Value -= damage
DamageDelt.Value += damage
amount.Value += 1
local function wodas()
goi.CanvasGroup.Amount.Size = UDim2.new(DamageDelt.Value/100,0,0,75)
local random = math.random(1,90)
local xnew = random/100
local wood2 = game.ReplicatedStorage.Wood:Clone()
wood2.Parent = Players.LocalPlayer.PlayerGui.Items
wood2.Position = UDim2.new(xnew,0,0.76,0)
wood2.TextLabel.Text = "+"..damage
local tween = Tween:Create(wood2, tweenInfo, {Position = woodPosition})
tween:Play()
wait(1.3)
wood2:Destroy()
end
if health.Value == 0 or health.Value < 0 then
print(health.Value)
wodas()
tweenlog:Play()
goi.CanvasGroup.Visible = false
goi.CanvasGroup.Amount.Size = UDim2.new(0.2,0,0,75)
amount:Destroy()
wood.Value += damage * 2
hit.Parent.Canbeattacked.Value = false
dbbb = true
task.wait(20)
tree.Tree.CFrame = CFrame.new(oldpos)
dbbb = false
hit.Parent.Canbeattacked.Value = true
end
if health.Value <= 100 and dbbb == true then
goi.CanvasGroup.Amount.Size = UDim2.new(DamageDelt.Value/100,0,0,75)
wodas()
wood.Value += damage
end
task.wait(1)
db = true
else
print(hit.Parent.Name)
end
end)
handle.Parent.Activated:Connect(function()
if canSwing then
canSwing = false
task.wait(1)
canSwing = true
end
end)