Now I am releasing an experience called “Samurai Era”.
As you can see the picture below, there is a region (colored with half transparent red)
where a player can fight against other players with a bamboo sword.
Blockquote
local hitRegionPart = script.Parent
local filter = OverlapParams.new()
filter.FilterDescendantsInstances = {}
filter.FilterType = Enum.RaycastFilterType.Whitelist
local parts = game.Workspace:GetPartsInPart(hitRegionPart, filter)
while true do
for _, v in pairs (parts) do
if v.Name == “Blade” then
v.Touched:Connect(function(otherpart)
if otherpart.Parent:WaitForChild(“Humanoid”) then
local hum = otherpart.Parent.Humanoid
hum:TakeDamage(5)
wait(1)
end
end)
end
end
end
Blockquote
There is no error but a player never take damage from the dummy in the region.
I don’t know what is wrong.
I appreciate if someone help me.
well for one, you’re running a while loop without any sort of waiting inside of it, that will lead to script timeout or whatever. second, you’re connecting a touched event to your blade each time you run this while loop IF there is a blade inside the regionpart.
If I’m reading it correctly, you’re not filtering anything. You have a Whitelist and put nothing in the filter descendants so nothing is getting picked up by the GetPartsInParts.
You’re basically saying:
you: Hey, I want you to ONLY detect when it hits these items
function: Ok, what items would you like me to detect?
you: These items: Filter = {}
An empty table. There are probably more errors and things missing but that was the first one I saw
Thank you for your reply. Yes, I think my current code has a lot of problems, so I think I should try Zone first and now writing the code. Thank you for your smart explanation easy to understand.
local Zone = require(game:GetService("ReplicatedStorage").Zone)
local container = workspace.SamuraiSchool.HitRegionPart
local zone = Zone.new(container)
local players = game:GetService("Players")
local weapons = game:GetService("ReplicatedStorage").Weapons
local shinai = weapons.Shinai
--local FORCE_FIELD_NAME = "SafeZoneForceField"
--local forceFieldTemplate = Instance.new("ForceField")
--forceFieldTemplate.Name = FORCE_FIELD_NAME
zone.playerEntered:Connect(function(plr)
local char = plr.Character
local hum = char:FindFirstChild("Huamnoid")
local clone = shinai:Clone()
clone.Parent = char
--hum:EquipTool(clone)
end)
zone.playerExited:Connect(function(plr)
local itemName = "Shinai" --Change this
if plr.Backpack:FindFirstChild(itemName) and plr.Backpack[itemName]:IsA("Tool") then
plr.Backpack.Shinai:Destroy()
end --Destroy Non-Equipped tool in inventory / Backpack
if plr.Character and plr.Character:FindFirstChild(itemName) and plr.Character[itemName]:IsA("Tool") then
plr.Character[itemName]:Destroy()
end --Destroy Equipped Tool
end)
This code works fine. And so I close this thread. Thank u so much for ur cooperation guys!