So I have this script that makes parts spin around the player (without rotating the parts but going around in a circle.) How would I make it stop on a specific one in front of the player, then make them disappear?
local character = workspace:WaitForChild("CleetusSama"):WaitForChild("HumanoidRootPart") -- test code to try out
local DISTANCE = 10 -- radius/distance to rotate from the player.
local increment = 0
local PartClone = game.ReplicatedStorage.CParts:Clone()
PartClone.Parent = game.Workspace
local parts = PartClone:GetChildren()
local offset = 360/#parts -- make a perfect angle distance for each part no matter how many parts by dividing a whole circle by the amount of parts.
local rs = game:GetService("RunService")
rs.Heartbeat:Connect(function(dt)
increment += dt * (math.abs(math.sin(tick() * 1)) * 125)
for i,v in pairs(parts) do -- v is the current part
local trueOffset = offset * i
v.Position = Vector3.new(character.Position.X + math.sin(math.rad(increment+trueOffset)) * DISTANCE,character.Position.Y ,character.Position.Z + math.cos(math.rad(increment+trueOffset)) * DISTANCE)
end
end)
I’m not completely sure what you meant, but I’m guessing you want it to always be in the same position relative to the character in a similar way to locking particles to a part. Here’s how to do that if so:
local character = workspace:WaitForChild("CleetusSama"):WaitForChild("HumanoidRootPart") -- test code to try out
local DISTANCE = 10 -- radius/distance to rotate from the player.
local increment = 0
local PartClone = game.ReplicatedStorage.CParts:Clone()
PartClone.Parent = game.Workspace
local parts = PartClone:GetChildren()
local offset = 360/#parts -- make a perfect angle distance for each part no matter how many parts by dividing a whole circle by the amount of parts.
local rs = game:GetService("RunService")
rs.Heartbeat:Connect(function(dt)
increment += dt * (math.abs(math.sin(tick() * 1)) * 125)
for i,v in pairs(parts) do -- v is the current part
local trueOffset = offset * i
v.CFrame = character.CFrame * CFrame.new(Vector3.new(math.sin(math.rad(increment+trueOffset)) * DISTANCE, 0, math.cos(math.rad(increment+trueOffset)) * DISTANCE))
end
end)
no, what it’s supposed to be doing is spinning around the player once, then it puts one specific one in front of the player, and disappears after a few seconds. Think of it like this; it’s a “character select screen” but the player has already selected the character, so it spins, and the character punches the one they are after it lands in front of them.
what you gave also helps as well though, because I was going to do that later, I just need to figure this problem out first.
In what way do you specify the specific one? If you want it to always do one specific one, naming it something different could help, that way once it’s done spinning, it can find the named one and move it in front of the player, or stop the script once the named on is close enough to the desired position relative to the player:
local cframe = torso.CFrame * CFrame.new(Vector3.new(2, 0, 0)
local vector = Vector3.new(cframe.X, cframe.Y, cframe.Z)
local dist = (part.Position - vector).magnitude)
if dist < 5 then
--bla bla bla
end
On the other hand though, if you want the player to decide which specific one it is, adding a click detector to them all and performing a function on the one clicked should do it.
Yes I understand that, but this is a different distance variable used for detecting how far the specific part is away from the desired end point in front of the player. You could make it so that it disconnects the renderstepped function once the distance is below a certain number and then run a different function.
local character = workspace:WaitForChild("CleetusSama"):WaitForChild("HumanoidRootPart") -- test code to try out
local DISTANCE = 10 -- radius/distance to rotate from the player.
local increment = 0
local PartClone = game.ReplicatedStorage.CParts:Clone()
PartClone.Parent = game.Workspace
local parts = PartClone:GetChildren()
local offset = 360/#parts -- make a perfect angle distance for each part no matter how many parts by dividing a whole circle by the amount of parts.
local rs = game:GetService("RunService")
local connection = nil -- so it stops doing it when you're done and they disappear
connection = rs.Heartbeat:Connect(function(dt)
increment += dt * (math.abs(math.sin(tick() * 1)) * 125)
for i,v in pairs(parts) do -- v is the current part
local trueOffset = offset * i
v.Position = Vector3.new(character.Position.X + math.sin(math.rad(increment+trueOffset)) * DISTANCE,character.Position.Y ,character.Position.Z + math.cos(math.rad(increment+trueOffset)) * DISTANCE)
end
local cframe = torso.CFrame * CFrame.new(Vector3.new(2, 0, 0))
local vector = Vector3.new(cframe.X, cframe.Y, cframe.Z)
local dist = (specificpart.Position - vector).magnitude
if dist < 2 then --checks if the desired part is within 2 studs away from the end point in front of the character, change amount if needed
for i, v in pairs(parts) do
v:Destroy() --or do whatever else you want to make them disappear
end
connection:disconnect()
end
end)
Oh I apologize, my typing is always messy and it frustrates the hell outta me when I’m trying to make something. Usually takes me like 5 times to remove all errors from a script of mine, lol. Anyway, I removed the typos from the original post.
local character = workspace:WaitForChild("CleetusSama"):WaitForChild("HumanoidRootPart") -- test code to try out
local DISTANCE = 10 -- radius/distance to rotate from the player.
local increment = 0
local PartClone = game.ReplicatedStorage.CParts:Clone()
PartClone.Parent = game.Workspace
local parts = PartClone:GetChildren()
local specificpart = PartClone.specificpart
local offset = 360/#parts -- make a perfect angle distance for each part no matter how many parts by dividing a whole circle by the amount of parts.
local rs = game:GetService("RunService")
local connection = nil -- so it stops doing it when you're done and they disappear
connection = rs.Heartbeat:Connect(function(dt)
increment += dt * (math.abs(math.sin(tick() * 1)) * 125)
for i,v in pairs(parts) do -- v is the current part
local trueOffset = offset * i
v.Position = Vector3.new(character.Position.X + math.sin(math.rad(increment+trueOffset)) * DISTANCE,character.Position.Y ,character.Position.Z + math.cos(math.rad(increment+trueOffset)) * DISTANCE
end
local cframe = character.CFrame * CFrame.new(Vector3.new(2, 0, 0)
local vector = Vector3.new(cframe.X, cframe.Y, cframe.Z)
local dist = (specificpart.Position - vector).magnitude
if dist < 2 then --checks if the desired part is within 2 studs away from the end point in front of the character, change amount if needed
for i, v in pairs(parts) do
v:Destroy() --or do whatever else you want to make them disappear
end
connection:disconnect()
end
end)
the errors are on the local in local vector and the end two lines above
local character = workspace:WaitForChild("CleetusSama"):WaitForChild("HumanoidRootPart") -- test code to try out
local DISTANCE = 10 -- radius/distance to rotate from the player.
local increment = 0
local PartClone = game.ReplicatedStorage.CParts:Clone()
PartClone.Parent = game.Workspace
local parts = PartClone:GetChildren()
local offset = 360/#parts -- make a perfect angle distance for each part no matter how many parts by dividing a whole circle by the amount of parts.
local rs = game:GetService("RunService")
local connection = nil -- so it stops doing it when you're done and they disappear
connection = rs.Heartbeat:Connect(function(dt)
increment += dt * (math.abs(math.sin(tick() * 1)) * 125)
for i,v in pairs(parts) do -- v is the current part
local trueOffset = offset * i
v.Position = Vector3.new(character.Position.X + math.sin(math.rad(increment+trueOffset)) * DISTANCE,character.Position.Y ,character.Position.Z + math.cos(math.rad(increment+trueOffset)) * DISTANCE
end
local cframe = torso.CFrame * CFrame.new(Vector3.new(2, 0, 0)) -- fixed typo
local vector = Vector3.new(cframe.X, cframe.Y, cframe.Z)
local dist = (specificpart.Position - vector).magnitude -- fixed typo
if dist < 2 then --checks if the desired part is within 2 studs away from the end point in front of the character, change amount if needed
for i, v in pairs(parts) do
v:Destroy() --or do whatever else you want to make them disappear
end
connection:disconnect()
end
end)
Okay, I opened it in a script on studio to make sure there’s no more. There shouldn’t be any left now. (Added the missing bracket to the local vector)
connection = rs.Heartbeat:Connect(function(dt)
increment += dt * (math.abs(math.sin(tick() * 1)) * 125)
for i,v in pairs(parts) do -- v is the current part
local trueOffset = offset * i
v.Position = Vector3.new(character.Position.X + math.sin(math.rad(increment+trueOffset)) * DISTANCE,character.Position.Y ,character.Position.Z + math.cos(math.rad(increment+trueOffset)) * DISTANCE)
end
local cframe = torso.CFrame * CFrame.new(Vector3.new(2, 0, 0))
local vector = Vector3.new(cframe.X, cframe.Y, cframe.Z)
local dist = (specificpart.Position - vector).magnitude
if dist < 2 then --checks if the desired part is within 2 studs away from the end point in front of the character, change amount if needed
for i, v in pairs(parts) do
v:Destroy() --or do whatever else you want to make them disappear
end
connection:disconnect()
end
end)
ok so it works partially but it doesn’t land on it in the middle it lands on it on the side, how would I fix that? i’m new to cframe (very new) also it just starts spinning and landing randomly after
Well, it detects when it’s 2 studs away from the end point, so if that’s too much for your prefference then you should change the number 2 to something smaller.
Example:
if dist < 0.25 then --for 0.25 stud radius
for i, v in pairs(parts) do
v:Destroy()
end
connection:disconnect()
end
Also, if you meant that it stops at the start, then you should make the chosen part spawn slightly already rotated so it doesn’t get too close in the beginning, or just make it so it doesn’t stop if a counting number isn’t above a required amount of rotations (The latter is likely better):
local n = 0
connection = rs.Heartbeat:Connect(function(dt)
increment += dt * (math.abs(math.sin(tick() * 1)) * 125)
for i,v in pairs(parts) do -- v is the current part
local trueOffset = offset * i
v.Position = Vector3.new(character.Position.X + math.sin(math.rad(increment+trueOffset)) * DISTANCE,character.Position.Y ,character.Position.Z + math.cos(math.rad(increment+trueOffset)) * DISTANCE)
end
local cframe = torso.CFrame * CFrame.new(Vector3.new(2, 0, 0))
local vector = Vector3.new(cframe.X, cframe.Y, cframe.Z)
local dist = (specificpart.Position - vector).magnitude
n = n + 1
if dist < 0.25 and n > 10 then --checks if the desired part is within 2 studs away from the end point in front of the character, change amount if needed
for i, v in pairs(parts) do
v:Destroy() --or do whatever else you want to make them disappear
end
connection:disconnect()
end
end)