Tocuh event help

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)

What is the handle’s parent? Assuming it’s a tool, it wouldn’t work because the tool doesn’t have a Touched function.

oh, then how would i do it so when the tool or anypart of it is touched

You’d want to make a hitbox around it, yes that’s it. Then look into spatial queries, we’re not here to spoon-feed code

Another thing you can try is to use GetChildren() on the tool in a for i, v loop, and use v:IsA() to get all the parts inside of the tool. There, you can use v.Touched:Connect(function(). That should work.

how would i use the v:IsA() here?

local v = handle.Parent:GetChildren()

v.Touched:Connect(function(hit)

An example would be like this:

for i, v in pairs(Tool:GetDescendants()) do
    if v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
        v.Touched:Connect(function()
            -- do stuff here
        end
    end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.