Ask AI on The Internet
Question: make a roblox scrip where when you touch a part it orbits around you
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 = TweenInfo.new( 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 = CFrame.new(part.Position, 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.
A new large language model has been made available since this question was asked.
To generate an updated answer from the new model, click the button below.
Think your answer is better than the AI's? Post it below.
Other Most Relevant Posts:
If you want your question answered by an AI, click here.
Post your own comment: