The Internet

Log In or Register

Digital illustration of a 3D Roblox character holding a part that orbits around them when touched

Ask AI on The Internet

Question: make a roblox scrip where when you touch a part it orbits around you

Asked by elite

0 Points

Log In or Register to Vote

The creation of such a script will involve using the tools of Roblox Studio along with a basic understanding of the Lua scripting language. Here is a simple example script that uses a touched event to make a Roblox part follow the player around: ```lua local part = game.Workspace.YourPart -- replace 'YourPart' with the name of your part in Workspace local function onPartTouched(otherPart) local humanoid = otherPart.Parent:FindFirstChild("Humanoid") -- check if the part that touched is part of a character if humanoid then local player = game.Players:GetPlayerFromCharacter(humanoid.Parent) -- get the player of the character if player then local distanceToPlayer = 5 local tweenInfo = 2, -- Duration of the tween (in seconds) Enum.EasingStyle.Linear, -- Easing style of the tween Enum.EasingDirection.InOut, -- Easing direction of the tween -1, -- Repeat count (negative for infinite) true, -- Reverses the tween on completion if true 0 -- Delay before repeating the tween (in seconds) ) local target = {} -- create a dummy table to animate target.Value = 0 -- this is the property we will animate -- create the tween local tween = game:GetService("TweenService"):Create( part, -- object to animate tweenInfo, -- information about the animation target -- properties to animate ) local function onHeartbeat() local playerPos = player.Character.HumanoidRootPart.Position -- calculate the position where we want to get the part to local desiredPos = playerPos + (part.Position - playerPos).Unit * distanceToPlayer part.CFrame =, desiredPos) target.Value = (desiredPos - part.Position).Magnitude tween:Play() end -- connect the function to run every frame game:GetService("RunService").Heartbeat:Connect(onHeartbeat) end end end part.Touched:Connect(onPartTouched) ``` Remember to replace `YourPart` with the name of the brick or object you want to orbit around the player. This script will cause the part to orbit 5 studs away from the player. The `distanceToPlayer` parameter can be adjusted accordingly. The part will not physically touch the player it will keep a distance of 5 studs between itself and the player. The part will move towards the position it should be if it's not already there, this is done every frame which creates the smooth motion and keeps the part around the player. Note: This script is unverified and might need minor tweaks as per your game environment.

Answered by gpt-4

July 24, 2023, 9:42 p.m.

0 Points

Log In or Register to Vote

Think your answer is better than the AI's? Post it below.

Please log in or sign up to post your answer.

This article was generated in part by one of OpenAI’s large-scale language-generation model, answering user elite's question. Images were generated with OpenAI's AI model, DALL·E 2. The Internet takes ultimate responsibility for the content of this publication.
If you want your question answered by an AI, click here.

Published: Monday, July 24, 2023

Comment Section