Just wondering, as the code im using isnt firing server with what i need
Im requiring it and running the module in a local script if it makes any difference
Yes and no. If you have a function in your module script and you call that from a server script, it will not work. But if you call that function from a local script then it will work
weird, im running it in a local script and its not firing, could be a issue in my part with the coding
That could be possible. Could you post both the local script and module script
The problem probably lies within the code not running, so add prints throughout the code to figure out where it stops. Many things could stop it, such as a loop, or even a condition returning false.
it goes all the way through, just isnt firing for some reason
Heres the module script code
-- Variables
local Hitboxes = {}
local Event = script.HitboxEvent
local SendOnlyHumanoids = false
-- Functions
local function StartingHitbox(hb, t)
if not Hitboxes[hb] or Hitboxes[hb] ~= true then Hitboxes[hb] = true end
if not Hitboxes[hb] and Hitboxes[hb] ~= true then Hitboxes[hb] = true end
while task.wait(1) do
print("Looping")
if Hitboxes[hb] and Hitboxes[hb] == true then
local ThingsTouching = workspace:GetPartsInPart(hb, if t["Op"] then t["Op"] else OverlapParams.new()) --workspace:GetPartBoundsInBox(hb.CFrame, hb.Size, if t["Op"] then t["Op"] else OverlapParams.new())
if #ThingsTouching > 0 then
print("l")
if SendOnlyHumanoids == true then
local temptable = {}
for i,v in ipairs(ThingsTouching) do
if v.Parent:FindFirstChild("Humanoid") and not table.find(temptable, v.Parent) then
table.insert(v.Parent)
end
end
if #temptable > 0 then Event:FireServer(temptable) end
else
print(ThingsTouching)
Event:FireServer(ThingsTouching)
end
end
else
coroutine.close()
end
end
end
local function AttachPositions(Model)
local PartSize, PartPosition = nil, nil
local PartSize = Model:GetExtentsSize()
local PartPosition = Vector3.new(
Model:GetPivot().X,
Model:GetPivot().Y,
Model:GetPivot().Z
)
return PartSize, PartPosition
end
-- Module
local HitBoxM = {}
HitBoxM.__index = HitBoxM
HitBoxM.CreateHitbox = function(Tool : Tool, Model : Model)
local tabled = {}
local PartHitbox = Instance.new("Part")
PartHitbox.Anchored = true
PartHitbox.CanCollide = false
PartHitbox.Transparency = 1
PartHitbox.Color = Color3.new(255,255,255)
local HitboxWeld = Instance.new("Weld")
local PartSize, PartPosition = AttachPositions()
PartHitbox.Size = PartSize
PartHitbox.Position = PartPosition
HitboxWeld.Part0 = Tool.Handle
HitboxWeld.Part1 = PartHitbox
PartHitbox.Parent = Tool
tabled["HitBoxPart"] = PartHitbox
setmetatable(tabled, HitBoxM)
return tabled
end
HitBoxM.SetupHitbox = function(Hitbox : Part)
local t = {}
t["HitBoxPart"] = Hitbox
setmetatable(t, HitBoxM)
return t
end
function HitBoxM:StartHitbox()
if not self["HitBoxPart"] or self["HitBoxPart"].ClassName ~= "Part" then warn("Tried Starting a hitbox without setup/creation") return end
local Hitbox = self["HitBoxPart"]
local d = coroutine.create(StartingHitbox)
coroutine.resume(d, Hitbox, self)
end
function HitBoxM:StopHitbox()
if not self["HitBoxPart"] or self["HitBoxPart"].ClassName ~= "Part" then warn("Tried Stopping a hitbox without setup/creation") return end
local Hitbox = self["HitBoxPart"]
if Hitboxes[Hitbox] then Hitboxes[Hitbox] = false else warn("There was no hitbox detected for: " .. Hitbox.Name .. ", Creating Detection"); Hitboxes[Hitbox] = false end
end
function HitBoxM:CreateParams(ThingsToFilter : Table)
local Op = OverlapParams.new()
Op.FilterType = Enum.RaycastFilterType.Blacklist
Op.MaxParts = 0
Op.FilterDescendantsInstances = if ThingsToFilter then ThingsToFilter else {}
self["Op"] = Op
end
return HitBoxM
And the local script
repeat wait() until game:IsLoaded()
local tool = script.Parent
local Handle = tool.Handle
local SwordModel = tool["Realistc Sword"]
local T_SwordParts = SwordModel:GetChildren()
local Hitboxmod = game.ReplicatedStorage.SimpleHitboxModule
local HBM = require(Hitboxmod)
local Hitbox = HBM.SetupHitbox(tool.HitBox)
local TableParams = {tool}
Hitbox:CreateParams()
Hitbox:StartHitbox()
If it does run
print(ThingsTouching)
then the problem is within the server script that handles the event.
it does print it, but ive tried hooking up just a blank thing and it doesnt even print
local event = script.Parent:WaitForChild("HitBoxEvent")
local function ToDo(Plr : Player , T)
print(Plr)
print(T)
for i, v in ipairs(T) do
print(v)
end
end
event.OnServerEvent:Connect(function()
print("sd")
end)
^ thats server forgot to add
Solved this, apparently scripts cant run in replicated storage which i didnt know