Rotating kill brick acting weird

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.


image

1 Like

Are you handling killing on the server? If so, that’s likely the issue. Try handling your kill bricks on the client.


This is the rotating script

image
Try this script. It worked for me. This should be what your looking for!

Rotating works just fine, I was just wondering if CylindricalConstraint had something to do with it messing up.

Same issue on the client side.

It does not. But if you use the script I provided it will only kill the player once their humanoid was touched the part.

not the humanoid it checks when the hit part’s parent has humanoid in it which can also be npc

Can I please have a video or screenshot?

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.

I made sure this loop does not cause any server lag. It tends to work perfectly and runs smoothly.

Switch out your kill script with mine, and try the loop.

robloxapp-20220108-1500397.wmv (997.5 KB)

Again the rotating is fine and also the kill script is fine too. But together they tend to mess up.

Not all loops cause lag. It just depends on what you’re doing, and how often you’re doing it.

Not from my experience. Anchored blocks that have their cframes rotated don’t really respond to .Touched.

Perhaps you could try a HingeConstraint instead? I haven’t had much issues with it in the past before.

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.

CylindricalConstraint had nothing to do with it, I had another script that was interfering with client-sided objects.