#Trying to make a part hover & spin above the player's head while following them but part gets stuck

4 messages · Page 1 of 1 (latest)

onyx crane
#

local part = script.Parent -- Reference to the part this script is in
local bobHeight = 0.3 -- How high the part will bob up and down
local bobSpeed = 2 -- Speed of the bobbing motion
local rotationSpeed = 2 -- Speed of the rotation in degrees per frame

local player = game.Players.LocalPlayer

local startPosition = part.Position
local timeElapsed = 0 -- Keeps track of the time for smooth bobbing

-- Function to update the part's position and rotation
local function updatePart()
local character = player.Character
local humRootPart = character.HumanoidRootPart

local offsetY = math.sin(timeElapsed * bobSpeed) * bobHeight
part.Position = humRootPart.Position + Vector3.new(0, offsetY, 0)


part.Orientation = part.Orientation + Vector3.new(0, rotationSpeed, 0)


-- Increment the time elapsed for smooth bobbing
timeElapsed = timeElapsed + wait(0.03)

end

-- Run the update function in a loop
while true do
updatePart()
end

night anchorBOT
#

studio** You are now Level 9! **studio

lyric vigil
#

Is this a client script?

#

Secondly, if you want it to be much smoother I would suggest moving this from a while loop to RenderStepped