-- Script Write by azmangg local Players = game:GetService("Players") local RunService = game:GetService("RunService") local mainPart = script.Parent local parts = {mainPart.Part1, mainPart.Part2, mainPart.Part3, mainPart.Part4} local offsets = {} local isFollowing = true local buttonPressed = false local characterMovementThreshold = 0.1 -- Calculate offsets for each part relative to the main part for _, part in ipairs(parts) do local offset = part.Position - mainPart.Position table.insert(offsets, offset) end -- Linear interpolation function local function lerp(a, b, t) return a + (b - a) * t end -- Function to make parts follow the head with bobbing effect local function follow(head) local currentHeadPosition = mainPart.Position local animationTime = 0 while isFollowing do local targetHeadPosition = head.Position + Vector3.new(0, 50, 0) -- Smoothly interpolate to the target position currentHeadPosition = lerp(currentHeadPosition, targetHeadPosition, 0.1) -- Bobbing effect local bobbingOffset = Vector3.new(0, math.sin(animationTime * 2) * 0.5, 0) mainPart.Position = currentHeadPosition + bobbingOffset for i, part in ipairs(parts) do part.Position = currentHeadPosition + offsets[i] + bobbingOffset end animationTime = animationTime + RunService.Heartbeat:Wait() end end -- Function to enable/disable character movement local function setCharacterMovementEnabled(character, enabled) local humanoid = character:FindFirstChildOfClass("Humanoid") if humanoid then humanoid.WalkSpeed = enabled and 16 or 0 humanoid.JumpPower = enabled and 50 or 0 end end -- Function to enable/disable character jump local function setCharacterJumpEnabled(character, enabled) local humanoid = character:FindFirstChildOfClass("Humanoid") if humanoid then humanoid.JumpPower = enabled and 50 or 0 end end -- Function to check if character is moving local function isCharacterMoving(character) local humanoid = character:FindFirstChildOfClass("Humanoid") if humanoid then return humanoid.MoveDirection.Magnitude > characterMovementThreshold end return false end -- Function to log events (for debugging) local function logEvent(eventMessage) print("[Event Log]: " .. eventMessage) end -- Function to handle button setup and interaction local function setupButton(character) local player = Players:GetPlayerFromCharacter(character) local playerGui = player:WaitForChild("PlayerGui") local screenGui = playerGui:WaitForChild("ScreenGui") local button = screenGui:WaitForChild("ImageButton") button.MouseButton1Click:Connect(function() if isCharacterMoving(character) then return end buttonPressed = not buttonPressed if buttonPressed then isFollowing = false setCharacterMovementEnabled(character, false) setCharacterJumpEnabled(character, false) local characterHeight = character.PrimaryPart.Size.Y local mainPartHeight = mainPart.Size.Y local extraDistance = characterHeight / 2 + mainPartHeight / 2 + 2 local characterCFrame = character.PrimaryPart.CFrame local targetPosition = characterCFrame.Position + characterCFrame.LookVector * 5 + Vector3.new(0, extraDistance, 0) local startPosition = targetPosition + Vector3.new(0, 100, 0) for _, part in ipairs(parts) do part.Position = startPosition + offsets[table.find(parts, part)] end for i = 1, 100 do local newPosition = lerp(mainPart.Position, targetPosition, 0.05) mainPart.Position = newPosition for i, part in ipairs(parts) do part.Position = newPosition + offsets[i] end RunService.Heartbeat:Wait() end local animationTime = 0 while buttonPressed do if isCharacterMoving(character) then buttonPressed = false isFollowing = true coroutine.wrap(follow)(character:WaitForChild("Head")) setCharacterMovementEnabled(character, true) setCharacterJumpEnabled(character, true) return end local bobbingOffset = Vector3.new(0, math.sin(animationTime * 2) * 0.5, 0) mainPart.Position = targetPosition + bobbingOffset for i, part in ipairs(parts) do part.Position = targetPosition + offsets[i] + bobbingOffset end animationTime = animationTime + RunService.Heartbeat:Wait() end else setCharacterMovementEnabled(character, true) setCharacterJumpEnabled(character, true) local targetPosition = mainPart.Position + Vector3.new(0, 100, 0) for i = 1, 100 do local newPosition = lerp(mainPart.Position, targetPosition, 0.05) mainPart.Position = newPosition for i, part in ipairs(parts) do part.Position = newPosition + offsets[i] end RunService.Heartbeat:Wait() end isFollowing = true coroutine.wrap(follow)(character:WaitForChild("Head")) end end) end -- Handle player addition and character addition Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local head = character:WaitForChild("Head") isFollowing = true coroutine.wrap(follow)(head) setupButton(character) logEvent("Character added and setup completed for player: " .. player.Name) end) logEvent("Player added: " .. player.Name) end) -- Function to handle errors local function handleError(errorMessage) warn("[Error]: " .. errorMessage) end -- Additional event logging for debugging local function logPartPositions() for i, part in ipairs(parts) do logEvent("Part" .. i .. " Position: " .. tostring(part.Position)) end end -- Periodically log positions for debugging RunService.Heartbeat:Connect(function() logPartPositions() end) -- Function to reset all parts to their initial positions local function resetPartsToInitialPositions() for i, part in ipairs(parts) do part.Position = mainPart.Position + offsets[i] end logEvent("Parts reset to initial positions") end -- Function to enable/disable all parts local function setPartsEnabled(enabled) for _, part in ipairs(parts) do part.Anchored = not enabled end logEvent("Parts " .. (enabled and "enabled" or "disabled")) end -- Function to check if player is in a specific region local function isPlayerInRegion(player, region) local character = player.Character if character and character.PrimaryPart then return region:ContainsPoint(character.PrimaryPart.Position) end return false end -- Function to move parts to a random position within a given region local function movePartsToRandomPosition(region) for _, part in ipairs(parts) do local randomPosition = region.CFrame.Position + Vector3.new(math.random(-region.Size.X/2, region.Size.X/2), 0, math.random(-region.Size.Z/2, region.Size.Z/2)) part.Position = randomPosition end logEvent("Parts moved to random positions within the region") end -- Setup a new button for resetting parts local function setupResetButton(character) local player = Players:GetPlayerFromCharacter(character) local playerGui = player:WaitForChild("PlayerGui") local screenGui = playerGui:WaitForChild("ScreenGui") local resetButton = screenGui:WaitForChild("ResetButton") resetButton.MouseButton1Click:Connect(function() resetPartsToInitialPositions() end) logEvent("Reset button setup completed for player: " .. player.Name) end -- Setup a new button for enabling/disabling parts local function setupTogglePartsButton(character) local player = Players:GetPlayerFromCharacter(character) local playerGui = player:WaitForChild("PlayerGui") local screenGui = playerGui:WaitForChild("ScreenGui") local togglePartsButton = screenGui:WaitForChild("TogglePartsButton") togglePartsButton.MouseButton1Click:Connect(function() local partsEnabled = parts[1].Anchored == false setPartsEnabled(not partsEnabled) end) logEvent("Toggle parts button setup completed for player: " .. player.Name) end -- Setup a new button for moving parts to a random position local function setupMovePartsButton(character, region) local player = Players:GetPlayerFromCharacter(character) local playerGui = player:WaitForChild("PlayerGui") local screenGui = playerGui:WaitForChild("ScreenGui") local movePartsButton = screenGui:WaitForChild("MovePartsButton") movePartsButton.MouseButton1Click:Connect(function() movePartsToRandomPosition(region) end) logEvent("Move parts button setup completed for player: " .. player.Name) end -- Extended setup for buttons Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local head = character:WaitForChild("Head") isFollowing = true coroutine.wrap(follow)(head) setupButton(character) setupResetButton(character) setupTogglePartsButton(character) setupMovePartsButton(character, workspace.RegionPart) logEvent("Extended setup completed for player: " .. player.Name) end) logEvent("Player added: " .. player.Name) end) -- Additional logging and error handling RunService.Heartbeat:Connect(function() pcall(function() logPartPositions() end) end)