Sword Area Regions

Hello,

So, yes, I still working on sword fighting. A lot of people helped me. ANYWAYS, this isn’t the thing going on here, I am still working on Sword Area Regions, I tried to use some regions online and I made but none of them worked, I also tried using touched events:

local IsTouching = false

    script.Parent.Touched:Connect(function(hit)
    	local hum = hit.Parent:FindFirstChild('Humoniod')
    	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    	if hum and not IsTouching then
    		IsTouching = true
    		hit.Parent:FindFirstChild('Humoniod'):EquipTool (plr.Backpack.ClassicSword)
    	end
    end)

    script.Parent.TouchEnded:Connect(function(hit)
    	local hum = hit.Parent:FindFirstChild('Humoniod')
    	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    	if hum and not IsTouching then
    		IsTouching = true
    		hit.Parent:FindFirstChild('Humoniod'):UnequipTools()
    	end
    end)

Any Region scripts? (Tool name Sword)

Thanks.

1 Like

Hey,

this is not a place where you ask for scripts, try to figure it by your own and then post if the script doesn’t work or something.

It seems like “Humanoid” is misspelled.

Touch Ended is very unreliable and I suggest you could use stuff like :GetTouchingParts()

local function CheckIfHumanoid(part)
local connection = part.Touched:Connect(function()end)
	local checking = part:GetTouchingParts()
	connection:Disconnect()
	return checking
end

while true do
local checkedAns = CheckIfHumanoid(workspace.GiveSwordRegion)
--print(#checkedAns)
for i,v in pairs(checkedAns) do
--print(v.Name)
if v:FindFirstChild('Humanoid') then
	print('giving player sword')
	if v:FindFirstChild('Sword') then
-- player already got a sword so just stop

			else
	-- No sword found
local cloneSword = game.ServerStorage.Sword:Clone()
cloneSword.Parent = v

end
	end
end
wait(1)
end

There might be some problems so maybe don’t just copy and paste