Basically i have a Folder and in this folder there are multiple Models. Into these models there are:
- parts
- an intvalue whose name is the name of a player
(here is an example)
I want to check if a player touches one of those parts (with specific requirements, for example if there is not the name of the player into the model itself), then there is a fireserver
So i tried to make a loop and added a debounce system, i want that if the player touches the part, then there is the fireserver ONLY 1 time, but i probably did a mistake because when a player touches one of the parts (with all the requirements), then it Fires exactly 2 times.
This is a local script
for _, part in pairs(game.Workspace.BodyParts:GetDescendants()) do
if part:IsA("Part") or part:IsA("MeshPart") then
local debounce = false
local connection = part.Touched:Connect(function(hit)
if debounce then
print("DEB")
return
end
if hit.Parent:FindFirstChildWhichIsA("Humanoid") and not debounce then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
print("HIT")
if player and not part.Parent:FindFirstChild(player.Name) then
part.CanTouch = false
print(player.Name.. " TOUCHED ".. part.Name.. " OF "..part.Parent:FindFirstChildWhichIsA("IntValue").Name)
debounce = true
TouchBodyPartEvent:FireServer(part.Name)
task.wait(2)
debounce = false
end
end
end)
end
end
Basically it prints "player.Name.. " TOUCHED ".. part.Name.. " OF “..part.Parent:FindFirstChildWhichIsA(“IntValue”).Name” exactly 2 times and it prints “HIT” 2 times and it doesn’t print “DEB” when the player touches
i don’t really understand where should i put the “debounce” and the reason why it doesn’t work, so if you know it may you please also explain why (besides fixing it). Thank you.


