local Module = {}
local RunService = game:GetService("RunService")
local RepStorage = game.ReplicatedStorage
local Modules = RepStorage.Modules
local Data = Modules.Data
local Main = require(Data.Main)
function Module:Raycast(Sword: Model, Combo: number, Move: string)
local Character = Sword.Parent
local Handle = Sword:FindFirstChild("Handle"):: BasePart
if not Handle then return end
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {Character}
local Attachments = {}
for i, Attachment in Handle:GetChildren() do
if not Attachment:IsA("Attachment") then continue end
if not string.find(Attachment.Name, "Attack") then continue end
Attachments[Attachment] = {}
Attachment:SetAttribute("OldPos", Attachment.WorldPosition)
end
local Data = Main.Data[Sword.Name][Move]:: Main.Move
#why does hitChar damage multiple times (NOT SOLVED)
1 messages · Page 1 of 1 (latest)
local Connection = game:GetService("RunService").PostSimulation:Connect(function()
for Attachment: Attachment in Attachments do
local Position = Attachment.WorldPosition
local OldPos = Attachment:GetAttribute("OldPos")
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {Character}
local Direction = Position - OldPos -- direction includes length
local Raycast = workspace:Raycast(Position, Direction, Params)
if not Raycast then continue end
local HitChar = Raycast.Instance.Parent
if not HitChar then continue end
local HitHumanoid = HitChar:FindFirstChild("Humanoid"):: Humanoid
if not HitHumanoid then continue end
local Info = Attachments[Attachment]
Info.CharsHit = Info.CharsHit or {}
local AmountHit = 0
for i = 1, #Info.CharsHit do
local v = Info.CharsHit[i]
AmountHit = v == HitChar and AmountHit + 1 or AmountHit
end
if AmountHit >= Data.MaxHits[Combo] then continue end
print(Combo)
table.insert(Info.CharsHit, HitChar)
HitHumanoid:TakeDamage(Data.Damage[Combo])
end
end)
return Connection
end
return Module
Sword is a model containing a part and multiple attachments as shown in the image. Combo is a number from 1-5, and Move is either M1 or M2 depending on the mousebutton1 or mousebutton2 but thats only for data recieving
why does hitChar damage multiple times (NOT SOLVED)
sub 1 solve