Hey
So i’m trying to do a damage script. But with region3.
So basically i created a Region3 around an enemy.
local regionPart = script.Parent
local pos1 = regionPart.Position - (regionPart.Size/2)
local pos2 = regionPart.Position + (regionPart.Size/2)
local region = Region3.new(pos1, pos2)
What im trying to do is whenever i attack, and my sword is in that region, it damages the NPC.
I’m trying to use a module script, to store my tools data in.
module script:
local tools= {
["Wooden Sword"] = {
["Damage"] = 15
},
["Test"] = {
["Damage"] = 10
}
}
return tools
I’m trying to check if “Wooden Sword” or any tool i add in the future is in that region, to damage the npc.
while true do
wait()
local partsInRegion = workspace:FindPartsInRegion3WithWhiteList(region, ToolsModule, 500)
for tools, part in pairs(partsInRegion) do
if EHum and tools then
print("Enemy found")
end
end
end
As you can see i tried to whitelist the module script, hoping it would whitelist every tool i add. But i don’t think it works like that.
Then i tried creating a table and adding all the Tools in that.
local tools = {}
for keyName, keyValue in pairs(ToolsModule) do
table.insert(tools, keyName)
end
And changed to
while true do
wait()
local partsInRegion = workspace:FindPartsInRegion3WithWhiteList(region, tools, 500)
for _, part in pairs(partsInRegion) do
if EHum then
print("Enemy found")
end
end
end
But with that i get an error:
‘Unable to cast value to Object’
I thought workspace:FindPartsInRegion3WithWhiteList needed a table?
Well, now i have no idea what to try next.
Sorry if this is unclear. But if you have any ideas, i’d like to hear them.
I’m extremely new to region3 and module scripts.
I just realised i never actually did anything with my tool.
Mhm, i still have no idea how to fix it.
Thank you for reading.