I don’t know what im doing wrong but this code seems to be printing twice when connecting part.Touched
local function onTagPad(tag)
local debounce = false
tag.Touched:Connect(function(hit)
if not debounce then
debounce = true
if (hit.Parent:FindFirstChild('Humanoid')~=nil) then
local char = hit.Parent
local HRP = char:FindFirstChild('HumanoidRootPart')
local rayOrigin = hit.Parent.PrimaryPart.CFrame.Position
local rayDirection = tag.CFrame.Position - rayOrigin
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {hit.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult.Normal then
if CollectionService:HasTag(tag, tagConfig.JumpPad) then
onJumpPad(tag, hit)
elseif CollectionService:HasTag(tag, tagConfig.DashPad) then
onDashPad(tag, hit)
end
end
end
print(hit)
task.wait(0.1)
debounce = false
end
end)
end
--// Tag Check
for _, part in (CollectionService:GetTagged(tagConfig.JumpPad)) do
onTagPad(part)
part.Orientation = Vector3.new(0,0,0)
end
CollectionService:GetInstanceAddedSignal(tagConfig.JumpPad):Connect(function(pad)
onTagPad(pad)
pad.Orientation = Vector3.new(0,0,0)
end)