#cframe issues
1 messages · Page 1 of 1 (latest)
Just add a magnitude check to see if the distance from the part to the player is less than your desired amount
hm ok
ok so im a bit stuck @umbral marlin
i got the magnitude thing
but how do i make it so when the magnitude is below a certain number, the part is stopped from getting any closer
im kinda new to c frames so idrk wat to do here
Just use a return statement to ignore the current iteration of the loop
you mean continue?
if i do return, it just makes the script do nothing
** You are now Level 5! **
No?
what is your code 😭
nope
continue is a jump statement
yeah LOL
bytecode wise they're completely different
return statement
continue statement
yeah i’m aware just not thinking rn
idk 😭
can you copy paste this code rq
imma change it
and explain my changes
idk really how to explain it well through words
it'd be better if i showed you visually
in practice
local Part = script.Parent.Parent
local ProximityPrompt = script.Parent
local Attached = false
ProximityPrompt.ActionText = "Attach?"
ProximityPrompt.HoldDuration = 0.6
ProximityPrompt.Triggered:Connect(function(Player)
local Character = Player.Character or Player:FindFirstChild("Character")
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
print(Player)
Attached = not Attached
if Attached == true then
Part.Anchored = false
Attached = true
ProximityPrompt.ActionText = "Unattach?"
while Attached do
local Distance = (Part.Position - HumanoidRootPart.Position).Magnitude
local LookVector = HumanoidRootPart.CFrame.LookVector
local PartPosition = Part.Position
ProximityPrompt.HoldDuration = 0.2
if Distance <= 5 then
return
end
Part.CFrame = CFrame.new(PartPosition, HumanoidRootPart.Position) -- make the part face the humanoid root part
print(Distance)
task.wait(0.002)
end
elseif Attached ~= true then
Part.Anchored = true
ProximityPrompt.ActionText = "Attach?"
ProximityPrompt.HoldDuration = 0.6
end
end)
it doesnt move when its anchored 😅
idk y
is this a serverscript
ye
or client
try this
local Part = script.Parent.Parent :: Part
local ProximityPrompt = script.Parent :: ProximityPrompt
local max = 10
local min = 5
local Attached = false
ProximityPrompt.ActionText = "Attach?"
ProximityPrompt.HoldDuration = 0.6
ProximityPrompt.Triggered:Connect(function(Player)
local Character = Player.Character or Player:FindFirstChild("Character") :: Model
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart") :: Part
print(Player)
Attached = not Attached
if Attached == true then
Part.Anchored = false
Attached = true
ProximityPrompt.ActionText = "Unattach?"
while Attached do
local Distance = (Part.Position - HumanoidRootPart.Position).Magnitude
local lv = (HumanoidRootPart.Position - Part.Position).Unit
local LookVector = HumanoidRootPart.CFrame.LookVector
local PartPosition = Part.Position
ProximityPrompt.HoldDuration = 0.2
if Distance > max then
Part.CFrame *= CFrame.new(
HumanoidRootPart.Position,
HumanoidRootPart.Position + lv * max)
elseif Distance < min then
Part.CFrame *= CFrame.new(
HumanoidRootPart.Position,
HumanoidRootPart.Position + lv * min)
end
Part.CFrame = CFrame.new(Part.Position, Part.Position - lv)
print(Distance)
task.wait()
end
elseif Attached ~= true then
Part.Anchored = true
ProximityPrompt.ActionText = "Attach?"
ProximityPrompt.HoldDuration = 0.6
end
end)
actually
i edited it
try this
it flies into the atmosphere 😭
local ProximityPrompt = script.Parent
local Attached = false
ProximityPrompt.ActionText = "Attach?"
ProximityPrompt.HoldDuration = 0.6
ProximityPrompt.Triggered:Connect(function(Player)
local Character = Player.Character or Player:FindFirstChild("Character")
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
print(Player)
Attached = not Attached
if Attached == true then
Part.Anchored = false
Attached = true
ProximityPrompt.ActionText = "Unattach?"
while Attached do
local Distance = (Part.Position - HumanoidRootPart.Position).Magnitude
local LookVector = HumanoidRootPart.CFrame.LookVector
local PartPosition = Part.Position
ProximityPrompt.HoldDuration = 0.2
if Distance <= 7 then
task.wait(0.01)
Part.CFrame = CFrame.new(PartPosition, HumanoidRootPart.Position)
continue
end
Part.CFrame = CFrame.new(PartPosition, HumanoidRootPart.Position) -- make the part face the humanoid root part
print(Distance)
task.wait(0.002)
end
elseif Attached ~= true then
Part.Anchored = true
ProximityPrompt.ActionText = "Attach?"
ProximityPrompt.HoldDuration = 0.6
end
end)```
i did this and it works
it'll bug out eventually
also btw i have no clue what prayer you're saying for it to move
that's only rotation
i think that's just because of anchored being false
and physics bugs
anyway i found the issue
local Part = script.Parent.Parent :: Part
local ProximityPrompt = script.Parent :: ProximityPrompt
local max = 10
local min = 5
local Attached = false
ProximityPrompt.ActionText = "Attach?"
ProximityPrompt.HoldDuration = 0.6
ProximityPrompt.Triggered:Connect(function(Player)
local Character = Player.Character or Player:FindFirstChild("Character") :: Model
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart") :: Part
print(Player)
Attached = not Attached
if Attached == true then
Part.Anchored = true
Attached = true
ProximityPrompt.ActionText = "Unattach?"
while Attached do
local Distance = (Part.Position - HumanoidRootPart.Position).Magnitude
local lv = (HumanoidRootPart.Position - Part.Position).Unit
local LookVector = HumanoidRootPart.CFrame.LookVector
local PartPosition = Part.Position
ProximityPrompt.HoldDuration = 0.2
if Distance > max then
Part.CFrame = CFrame.new(
HumanoidRootPart.Position,
HumanoidRootPart.Position + lv * max)
elseif Distance < min then
Part.CFrame = CFrame.new(
HumanoidRootPart.Position,
HumanoidRootPart.Position + lv * min)
end
Part.CFrame = CFrame.new(Part.Position, Part.Position - lv)
print(Distance)
task.wait()
end
elseif Attached ~= true then
Part.Anchored = true
ProximityPrompt.ActionText = "Attach?"
ProximityPrompt.HoldDuration = 0.6
end
end)
idk either
oh my god
i put *=
and not =
@frank depot
sorry i was in #📜︱scripting so i didn't see
but yeah
THIS
should work
recopy
if it works i'll explain why it does
i alr fixed it i think but lemme see
hm it sometimes goes under the player so then u can just fly on top of it 😭
yeah
that's this
i mean it doesnt rlly seem buggy
yeah

