Hello, i have spawner system but i need to check every second if part named hitbox is touching script.parent
Soo far i tried this but it stops working randomly:
script.Parent.Touched:Connect(function(brick)
if brick.Name == "hitbox" then
script.Parent.Parent.Folder.Two.Value = "1"
end
end)
script.Parent.TouchEnded:Connect(function(brick)
if brick.Name == "hitbox" then
script.Parent.Parent.Folder.Two.Value = "0"
end
end)
while wait(1) do
local touchingParts: table = script.Parent:GetTouchingParts()
for _, part in pairs(touchingParts) do
if (part.Name == "hitbox") then
-- A part named "hitbox" is touching script.Parent
end
end
end
This could work in theory but problem is that i need to set the value to 0 if it isn’t touching
while wait(1) do
local touchingParts = script.Parent:GetTouchingParts()
for _, part in pairs(touchingParts) do
if (part.Name == "hitbox") then
script.Parent.Parent.Folder.One.Value = 1 -- This works just fine!
else
script.Parent.Parent.Folder.One.Value = 0 -- However this not, if value is 1 some random brick can overwrite it and set it to 0
end
end
end
while wait(1) do
local touchingParts: table = script.Parent:GetTouchingParts()
local hasHitbox: bool = false
for _, part in pairs(touchingParts) do
if (part.Name == "hitbox") then
hasHitbox = true
break
end
end
if (hasHitbox) then
script.Parent.Parent.Folder.One.Value = 1
end
end