My issue is that I have a rotating kill brick, rotating at the very center. I use a CylindricalConstraint to make it rotate and it acts very weird when killing the player. Sometimes it will kill the player way before they have even touched the block and sometimes it doesn’t kill them at all. It has never killed the player when they actually touched the block though.
for i, v in pairs(game:FindFirstChild("Workspace"):FindFirstChild("KillBricks"):GetDescendants()) do
if v.Name == "KillBrick" then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = 0
end
end)
end
end
This script working perfectly fine on every kill brick, except the rotating ones.
Our kill scripts are generally the same, but your rotating script uses a loop, I generally try to stay away from repeating loops because they tend to cause server lag.
Instead of using a CylindricalConstraint, try using code to rotate the parts as suggested by others like so:
local CollectionService = game:GetService("CollectionService")
local rotatingParts = CollectionService:GetTagged("RotatingPart")
local inc = 0.15
for _, part in pairs(rotatingParts) do
task.spawn(function()
while true do
part.CFrame *= CFrame.fromEulerAnglesXYZ(0, inc, 0)
task.wait(1/45)
end
end
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid.Health > 0 then
hit.Parent.Humanoid.Health = 0
end
end)
end
The method I used is 100% pseudo-coded and not tested. This also assumes you tagged every part you want to rotate with a “RotatingPart” tag.