#cframe issues

1 messages · Page 1 of 1 (latest)

frank depot
umbral marlin
frank depot
#

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

umbral marlin
frank depot
#

if i do return, it just makes the script do nothing

hidden charmBOT
#

studio** You are now Level 5! **studio

frank depot
#

if i do continue, i crash

#

😭

umbral marlin
latent turret
#

what is your code 😭

umbral marlin
#

Ig both work

#

depends on their code

latent turret
#

not necessarily

#

any loop works

umbral marlin
#

yessecarily Thumbs

#

it’s easier to j return

latent turret
#

nope

umbral marlin
#

nvfm

#

my brain ain’t working

#

im going to sleep crying

latent turret
#

continue is a jump statement

frank depot
umbral marlin
#

yeah LOL

latent turret
#

bytecode wise they're completely different

latent turret
#

continue statement

umbral marlin
#

yeah i’m aware just not thinking rn

latent turret
#

you're setting the cframe directly

frank depot
latent turret
#

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

frank depot
#

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

latent turret
#

is this a serverscript

frank depot
#

ye

latent turret
#

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

frank depot
latent turret
#

oh

#

i know why

frank depot
#
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

latent turret
#

it'll bug out eventually

frank depot
#

probably

#

😭

latent turret
#

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

latent turret
#
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)
frank depot
#

idk either

latent turret
#

i forgot to anchor the part

#

fuck i commented it out

#

do that

frank depot
#

the magnitude slowly rises

#

it keeps getting flung into space 😭

latent turret
#

oh my god

#

i put *=

#

and not =

#

@frank depot

#

but yeah

#

THIS

#

should work

#

recopy

#

if it works i'll explain why it does

frank depot
#

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 😭

latent turret
#

yeah

latent turret
frank depot
latent turret
#

yeah

frank depot
#

i actually changed the position

#

instead of doing the weird rotating thingy