Hi, @TeamSwordphin. I have an issue (see the following picture and a part of the code):
...
if self.Hitbox then self.Hitbox:Deinitialize() end
self.Hitbox = RaycastModule:Initialize(newWep.Hitbox)
self.Hitbox.OnHit:Connect(function(_, Humanoid)
print(Humanoid)
end)
for Name, Anim in pairs(Anims) do
if string.match(Name, "ClassAttack") then
Anim:GetMarkerReachedSignal("HitStart"):Connect(function()
self.Hitbox:HitStart() -- Error: function not found. (Line 69)
end)
Anim:GetMarkerReachedSignal("HitStop"):Connect(function()
self.Hitbox:HitStop() -- Error: function not found. (Line 72)
end)
end
end
repeat wait()
print(self.Hitbox)
until false
...
I have a script that swings the sword and when it reaches a certain marker in the animation, it will start/stop the rays. But I get this error:
The first few swings after the character spawns, it doesnât error, but also no rays. All the swings after that shows the âattempt to call a nill valueâ error.
My presumptions lies on the fact that the table changes from âHitbox for instance âŚâ to {âŚ}, which causes the error, because the function isnât there or isnât .__indexed. Any idea why this issue happens?
I tried debugging my code from the inside out and it keeps showing this error.
No, I havenât messed with your module.
EDIT 1: Not parenting the hitbox part (aka the sword) to a descendant in workspace seems to removes the issue, new issue: I donât have a sword now to swing.
What was the problem: the hitbox wasnât welded to the sword, so it got destroyed once it reached Workspaceâs hell.
But have you tried it? An unanchored part created by the server doesnât calculate itâs physics when thereâs a player nearby that can do the calculating for the server.
Looks like you are anchoring the character, even when you anchor the character they will still retain velocity and this could possible mess up the attachments positions which Iâve seen before with issues like fastcast bullets spawning under the workspace.
So set the characters velocity or now assembly linear velocity to zero when anchored and see if that works
Otherwise itâs a server to client replication issues idk just guessing at this point.
It does indeed seem like a server replication issue. If you are using this module server-sided, itâs definitely seeing the sword position differently on the server-side due to latency. Unfortunately there isnât really a fix for this since technically there is nothing wrong from the moduleâs standpoint. I wouldnât worry too much about this if jumping off a cliff isnât the main part of the game. If you need accuracy, you should use this module client sided and send the hit target to the server as an alternative method (with sanity checks of course).
Hello @TeamSwordphin, great module! I was thinking if you would like to be able to add a thing to your module I made when it is fully finished. It can be used instead of set points/ attachments because this will get the part size and make a grid with positions on it. (The small dots are handle adornments)
Hey I Recently was trying to make still hitboxes that would stay in place, but they wonât hit if the player is standing still (sometimes). The red lines appear and they all go throught the player but it wonât detect them. Thanks for helping.
local hitbox = game.Workspace.Part
local hb = RayHB:Initialize(hitbox)
for i , v in pairs(hitbox:GetChildren()) do
for i , k in pairs(hitbox:GetChildren()) do
if v ~= k then
hb:LinkAttachments(v,k)
end
end
end
hb:HitStart(.2)
hb.OnHit:Connect(function(hit,hum)
print(hum.Parent)
if game.Players:GetPlayerFromCharacter(hum.Parent) then
game.ReplicatedStorage.Events.ClassEvents.Class2.Ab2:FireServer(hum)
end
end)
Thatâll be great! Iâll be sure to credit you once itâs finished! I know this will help a lot of people and save a lot of time!
@ncs03082 Looks like thereâs a problem on how I wrote the raycastParams for the red line visualizers in the module. It actually does work but for context, the module isnât ignoring the debug red lines (so therefore they keep hitting the redlines thinking they are actual targets). Try ignoring the terrain in the meantime (which is where the red lines are parented to) and see if it works:
local hb = RayHB:Initialize(hitbox, {workspace.Terrain})
This should be fixed in the next module update. Thanks!
The problem that @ncs03082 has, might also happen to many people so I was thinking you should use handle adornments to avoid the rays hitting the debug parts. Secondly, so that people that have other parts in parented to terrain would not have the parts blacklisted.
it would be nice if u gave a parameter to set the gap between 2 points and i have code for smthg similar to this if it might help u, i used it for making attachments automatically
for i= part.Position.Y - part.Size.Y/2, part.Position.Y + part.Size.Y/2,0.75 do
for x = part.Position.X-part.Size.X/2,part.Position.X + part.Size.X/2,1 do
local currattach = Instance.new("Attachment");
currattach.Name = "DmgPoint";
currattach.Parent = part;
currattach.WorldPosition = Vector3.new(x,i,currattach.WorldPosition.Z);
end
end
How would you make a functioning sword that is reliable with this module? I tried doing this method, firing the remote from a local script inside a sword. However, it does not work, and I think I found the reason.
Even tho I passed in the ignore argument in local RaycastHitBox:Initialize(handle, dontDamage), the newHitBox.OnHit still fires picking up the humanoid that is told to be ignored, then not allowing any other humanoids to be detected as it can only damage one humanoid at a time. When I take out the ignore argument, the newHitBox.OnHit actually fires, which it does not when the ignore argument is left in RaycastHitbox:Initialize.
Help would be appreciated I am struggling greatly with this issue
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")
local SwordDamage = require(ReplicatedStorage.Modules.SwordDamage)
local RaycastHitbox = require(ReplicatedStorage.Modules.RaycastHitbox)
local SwordRaycastPositions = require(ReplicatedStorage.Modules.SwordRaycastPositions)
local cooldown = require(ReplicatedStorage.Modules.Cooldown).cooldownValue
local humanoidsKilled = {}
ReplicatedStorage.Remotes.OnSwing.OnServerEvent:Connect(function(player, handle)
local playerTeam = nil
local playerToDamage = nil
if remoteData[player.Name].SwingHandlingDebounce == true then return end
local debounce = remoteData[player.Name].SwingHandlingDebounce
if not debounce.Value then
print("hello1")
debounce.Value = true
local character = player.Character or player.CharacterAdded:Wait()
local dontDamage = {character}
local damage = require(ReplicatedStorage.Modules.SwordDamage)[handle.Parent.Name]
local newHitBox = RaycastHitbox:Initialize(handle, dontDamage)
newHitBox:SetPoints(handle, SwordRaycastPositions[handle.Parent.Name])
newHitBox.OnHit:Connect(function(hit, humanoid)
--just for test purposes on dummies
humanoid:TakeDamage(10)
--local playerTeam = player.Team
--local playerToDamage = Players:GetPlayerFromCharacter(humanoid.Parent)
--if playerToDamage ~= nil then
-- print(player.Team)
--if tostring(playerToDamage.Team) == tostring(player.Team) then
-- print("DO NOT DAMAGE")
--elseif tostring(playerToDamage.Team) ~= tostring(player.Team) then
-- print("DAMAGE, THEY ARE THE ENEMY")
-- humanoid:TakeDamage(damage)
--end
--end
-- local leaderstats = player.leaderstats
--local kills = leaderstats.Kills
-- local enemyTeam = nil
-- local playerTeam = player.Team
--[[if table.find(humanoidsKilled, humanoid) == nil and humanoid.Health <= 0 then
table.insert(humanoidsKilled, humanoid)
kills.Value = kills.Value + 1
elseif table.find(humanoidsKilled, humanoid) == nil and humanoid.Health >= 0 then
table.remove(humanoidsKilled, humanoid)
end]]
end)
newHitBox:HitStart()
wait(cooldown)
newHitBox:HitStop()
debounce.Value = false
end
end)
At first glance, that should be working correctly. Are you sure you didnât set the hitboxâs raycastParams to Whitelist by accident somewhere? Have you modified the module in any way?
Does the âhandleâ ever disappear if the character respawns? The hitbox will still be blacklisting the characterâs old model if it doesnât. You can try modifying the raycastParams of the hitbox directly to see if this fixes it: