Right, so I'm trying to make swords here. As you can see from the title, I'm using module scripts to deal with all the logic or whatever. Now, I have a region3 defined in my module script, and if a player is in that region3 I want them not to take damage. Now, CFrames, Region3s, all that kind of stuff has always been a weak side to me, so I found online some code for that and I modified it a bit to match what I wanted. Now with that, I tested the thing on a local server and whether I was in the region or not it would still kill the player. I need help with that, thanks.
This is my function inside of the module script:
function module.onTouchDamage(h)
local afkregion = Region3.new(game.Workspace.afkregion1.Position, game.Workspace.afkregion2.Position)
local isPlayerInRegion
if h.Parent:FindFirstChild("Humanoid") then
local char = h.Parent
local whitelist = char:GetChildren()
----------------------------------------
local partsInRegion = game.Workspace:FindPartsInRegion3WithWhiteList(afkregion, whitelist)
if #partsInRegion >= 1 then
isPlayerInRegion = true
print(#partsInRegion)
print(partsInRegion[1].Name)
else
isPlayerInRegion = false
end
----------------------------------------
if isPlayerInRegion == false and char:WaitForChild("CanTakeDamage").Value == true then
return true
else
return false
end
end
end
This is a part my of script inside the sword.
sword.Touched:Connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
local char = h.Parent
local player = sword.Parent.Parent.Parent --Ik i used 4 parents in a row but you get it
if char.Name ~= player.Name then
local doDamage = module.onTouchDamage(h)
print(doDamage)
if doDamage == true then
char.Humanoid:TakeDamage(dmg.Value)
end
end
end
end)
All variables are defined
