Returned key with metatable becomes nil, why?

I’m trying to create a hitbox on character’s table then use an bindable function to get that table accorss servers but it errors.

local Touched =  RisytalEngine:ReturnF((...), "ev").GetHB:Invoke("RAH")
Touched.DetectionMode = 2
task.wait(0.7)
Touched:HitStart()
---
function RA(Part, Params)
	local Values = {}
	for _,v  in game:GetService("ServerStorage").__CORE.RisytalStuff.Rightarm:GetChildren() do
		table.insert(Values, v.Position)
	end
	local T = Hitbox.new(Part)
	T.RaycastParams = Params
	T:SetPoints(Part, Values)
	return T
end
local PHData = {
	["RLH"] = RisytalEngine:ReturnHit(Character["Right Leg"], Parms),
	["RAH"] = RA(Character["Right Arm"], Parms)
}
EventsFolder.GetHB.OnInvoke = function(Hit)
	return PHData[Hit]
end

The error: attempt to call missing method 'HitStart' of table

4 Likes

This method doesn’t exist basically.

1 Like

But It’s suppose to exist! It does when I print it!

Uhh well could you show the output and code where you printed it?

No offense, but this code is borderline unreadable. Abbreviating things requires context, and that’s context which we do not have. Also, this appears to use some kind of framework that you don’t mention?

It exists when I start the hitbox outside a dictionary. Hold
@Pokemoncraft5290 I’m using Raycast Hitbox 4.01: For all your melee needs! to create and store hitboxes in a table, since I had no other ways to store them, then I figured I’ll use a bindable function to get the table from across every script. But that apparently breaks the whole framework. Since this is the normal to create hitboxes.

local newHit = HitboxManager.new(Tool.Handle)
newHit.RaycastParams = Params
newHit.OnHit:Connect(function(Hit, VictimHumanoid:Humanoid?)
end)
newHit:HitStart() -- Start it

Creating a new hitbox outside a dictionary seems to work but I wanna store them in a table to easier access!

Oh ryt I see the issue now, HitStart is inside the metatable of the original module, however bindable functions has this limitation where metatables are lost during transfer

1 Like

Aw man, is there any fixes? My old method was to create a new hitbox for everything which caused a lot of memory issues.
Found a similar issue. BindableEvent can't return metatables after firing

Are you using a modular architecture?

Mmm, I don’t think so, that’s on raycasthitbox module.

function RaycastHitbox.new(object: any?)
	local hitbox: any

	if object and CollectionService:HasTag(object, DEFAULT_COLLECTION_TAG_NAME) then
		hitbox = HitboxData:_FindHitbox(object)
	else
		hitbox = setmetatable({
			RaycastParams = nil,
			DetectionMode = RaycastHitbox.DetectionMode.Default,
			HitboxRaycastPoints = {},
			HitboxPendingRemoval = false,
			HitboxStopTime = 0,
			HitboxObject = object,
			HitboxHitList = {},
			HitboxActive = false,
			Visualizer = SHOW_DEBUG_RAY_LINES,
			DebugLog = SHOW_OUTPUT_MESSAGES,
			SignalType = RaycastHitbox.SignalType.Single,
			OnUpdate = Signal.new(RaycastHitbox.SignalType.Single),
			OnHit = Signal.new(RaycastHitbox.SignalType.Single),
			Tag = DEFAULT_COLLECTION_TAG_NAME,
		}, HitboxData)

		hitbox:_Init()
	end

	return hitbox
end

No I don’t think you got me, I was asking if your game uses scripts or module scripts to a greater extent?

I used a modulescript to get the table, but that also doesn’t work, so I opted in for remote functions.

Actually module scripts ought to work in this scenario. Your best bet is to create a module named Hiitbox and add utility methods called :AddHitbox :GetHitbox and so on. Then from your main scripts, you would require this Hitbox module and instead of:

local Touched =  RisytalEngine:ReturnF((...), "ev").GetHB:Invoke("RAH")

you would do:

local Hitbox = require(ReplicatedStorage.Hitbox)
local Touched =  Hitbox:GetHitbox("RAH")

Since module communication has no limitations like BindableFunctions, you would be able to call all the methods of the hotbox including HitStart

The issue is, like I said, I did the same with modules, but classes become nil, Since I store the hitboxes in a dictionary with the player name as an identifier.

That should have worked just fine

I figured I’ll use this in both character script and main game script.

function CheckHitbox(Object, Character)
	if RaycastHitbox:GetHitbox(Object) == nil then
		print("is nil")
		local Parms:RaycastParams? = RaycastParams.new()
		Parms.FilterDescendantsInstances = {Character, workspace.__SPAWNEDSTUFF, workspace.Filter}
		Parms.FilterType = Enum.RaycastFilterType.Exclude
		return RisytalEngine:ReturnHit(Object, Parms)
	end
	print("its not nil")
	return RaycastHitbox:GetHitbox(Object)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.