I’m having issues with hit detection using the .Touched event as I tween a part from a tool’s Handle to a Mouse.Hit.Position.
I knew this would come up as the .Touched event does not fire on a tweening object that is anchored, however I do not know of a way around it. I have tried welding a hitbox part to a CFrame-tweening part and using the .Touched event for the hitbox part, but it also does not seem to fire.
The end goal is that the tweening ball, as it touches a player, will damage that player. Excluding the Handle and wielding player from the touched parts.
A visual; the last throw printed HumanoidRootPart
, Torso
, and Left Arm
.
dodgeball_tweening_test_and_failure.wmv (299.1 KB)
Here is the Script within the tool that does tweening and (hopefully soon) hit detection;
local tool = script.Parent.Parent
local event = script.Parent:WaitForChild("RemoteEvent")
local tweenService = game:GetService("TweenService")
local debounce = false
local airspeed = 100
event.OnServerEvent:Connect(function(player, mousePos)
if debounce == false then
--disable tool
debounce = true
tool.Handle.Transparency = 1
--make ball
local ball = Instance.new("Part")
ball.Shape = Enum.PartType.Ball
ball.Position = tool:WaitForChild("Handle").Position
ball.Color = Color3.fromRGB(117, 0, 0)
ball.Size = Vector3.new(2,2,2)
ball.Material = Enum.Material.Neon
ball.Anchored = true
ball.Parent = game.Workspace
ball.CanCollide = false
--tween settings
local goal = {}
goal.Position = mousePos
local distance = (mousePos - tool:WaitForChild("Handle").Position).Magnitude
local airtime = distance/airspeed
local tweenInfo = TweenInfo.new(airtime, Enum.EasingStyle.Linear)
--tween
local tween = tweenService:Create(ball, tweenInfo, goal)
tween:Play()
--attempted to use .Touched to find when the ball hits a player, however .Touched does not work correctly as the part is being tweened
ball.Touched:Connect(function(otherPart)
if otherPart ~= tool.Handle then
print(otherPart.Name)
end
end)
tween.Completed:Connect(function()
task.wait(1)
ball:Destroy()
debounce = false
tool.Handle.Transparency = 0
end)
end
end)
Here is the LocalScript within the tool that gets mouse details;
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local tool = script.Parent.Parent
local event = script.Parent:WaitForChild("RemoteEvent")
mouse.TargetFilter = game:GetService("Players").LocalPlayer.Character and script.Parent
tool.Activated:Connect(function()
if mouse.Target ~= nil then
local hit = mouse.Hit
--print(hit.Position)
event:FireServer(hit.Position)
end
end)
Thank you for any help.