Afternoon all!
Its my first time using raycasting in this manner, but I wanted to ask advice on how I should go about finding a raycast of a sword (tool) when its activated and playing an animation (1 minute), and detecting if the raycast hits another players character.
Why am I trying to achieve this?
Im attempting to add more stud range to attack range to more OP swords in my game.
Current code:
local list = {}
for _,players in pairs(game.Players:GetPlayers()) do
if players.Character then
table.insert(list,players.Character)
end
end
local rParams = RaycastParams.new()
rParams.FilterType = Enum.RaycastFilterType.Whitelist
rParams.FilterDescendantsInstances = list
local rParams2 = RaycastParams.new()
rParams2.FilterType = Enum.RaycastFilterType.Blacklist
rParams2.FilterDescendantsInstances = {t.Handle,character:GetChildren()}
local raycastResult = workspace:Raycast(t.Handle.Position, t.Handle.CFrame.LookVector * 5,rParams2)
print(raycastResult)
local rayOrigin = Vector3.new(0, 0, 0)
local rayDirection = Vector3.new(0, -100, 0)
local char = nil
if raycastResult then
if raycastResult.Instance.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.Remote.Notification:FireAllClients({
Type = "Notification",
Text = player.Name .. "<b>Attacked</b> \n ".. raycastResult.Instance.Parent.Name,
Duration = 10,
})
end
else
warn("No raycast result!")
end
Would it be best to create a loop during the animation is playing? if so what type of loop should I use?
Thanks!