Make a Smooth rotating killing bar

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A rotating bar that kills player on touch, as smooth as possible.

  2. What is the issue? Include screenshots / videos if possible!


    I first tried with a hinge constraint but due to the client and server’s discrepancy, the line would kill the player even without touching it… Now I made a CFrame updating with the while do iteration but it seems choppy.
    I’ve been thinking if it was a better solution to use an hinge constraint but let the touched event get called from the HumanoidRootPart instead from the bar?

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    No not really, I am trying with a CFrame but it looks choppy…

4 Likes

What about tween service, huh?

3 Likes

yeah, i said that man, why did you copy me? :frowning:

1 Like

I had the same opinion before I read your reply.
I’ll delete mine if that makes you feel any better.

1 Like

It’s gonna become more choppy, and I want it to spin endlessly

1 Like
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local part: BasePart = nil -- your spinner

local state = false
local speed = 10

type void = nil

local function start(): void
	if not state then
		state = true
		
		local nextCFrame = part.CFrame * CFrame.Angles(0, math.rad(5), 0)
		local connection; connection = runService.PostSimulation:Connect(function(dt)
			if state then
				nextCFrame = part.CFrame * CFrame.Angles(0, math.rad(5), 0)
				part.CFrame = part.CFrame:Lerp(nextCFrame, dt * speed)
			elseif part.CFrame == nextCFrame then
				connection:Disconnect()
			else
				part.CFrame = part.CFrame:Lerp(nextCFrame, dt * speed / 2)
			end
		end)
	end
end

local function stop(): void
	if state then
		state = false
	end
end

start()

use start() and stop() functions to interact with ur spinner


demonstration:

2 Likes

This sounds like the best solution, I should call it on the server, right? Oh and also, may you explain it a bit if possible? Thank you.

1 Like

oh, okay. thx :smiley: but now you can take this comment for ya

2 Likes

Yes, you must create a server script and specify the part that should spin. You can also speed it up in real time if you need it.

As for the explanation, the CFrame class has a built-in Lerp function. Lerp is a linear function similar to what TweenService uses. 1 argument is the beginning, the second is the end and the third moment in the line graph. That is, 0 is the start and 1 is the end, with this you can move your part smoothly. If you are not familiar with RunService, I encourage you to do so as it is a better solution than loops.

3 Likes

I agree, lerp is a good solution because it gives you the ability to change the rotation speed at any time.

3 Likes

actually yeah, but tween service is good too.

1 Like

You could use TurnVelocity, which doesn’t require scripting.

2 Likes

This definitely works well!! Thank you and thank to everyone who dedicated their time to help me in this matter! Good luck to any of y’all upcoming projects and have a wonderful day!

1 Like

Actually stop using deprecated stuff. It makes me want to kill myself

1 Like

TurnVelocity isn’t deprecated.

1 Like

Wouldn’t BodyGyro be better in situations like these? Setting CFrame constantly is bound to consume memory & be resource intensive.

1 Like

I know! But when more laggy devices joins in it slows down and it causes some mess :frowning:

1 Like

That’s because the NetworkOwnership is always switching to the nearest player, simple set that ownership to always be the server to avoid lag replicating on the spinner.

NetworkOwnership API can only be called on the server (via serverscripts), and you can set ownership by following the example:
BasePart:SetNetworkOwnership(player?)
If you leave the parameter blank, or set it to nil, the ownership will direct to the server.

2 Likes

Unfortunately this won’t work since this API only works with unanchored parts.

1 Like

Oh, I have tried it before but I used HingeConstraint… I’ll try again with BodyGyro ?

1 Like