#Align position not working

1 messages · Page 1 of 1 (latest)

wanton zephyr
#

yo i tried using align position but it aint working ..

gritty yew
#

Send the script

#

Like a image

#

Maybe

wanton zephyr
#

if you want the full script tell me

#

but it doesnt even work when i manually create two parts with 2 attachment and an align position

silk mesa
#

the one which has attachment0 in it

wanton zephyr
silk mesa
#

strange

#

i think its proibably because of the velocity

#

but im not sure

wanton zephyr
#
local tool = script.Parent

local camera = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local UIS = game.UserInputService

local result = nil

local grabpart = nil

local align = nil

local attachment0 = nil
local attachment1 = nil

print("yes")
local grabbing = false
local running = false

tool.Activated:Connect(function()
    running = true
    while running do
        wait(.002)

        local mousePos = UIS:GetMouseLocation()
        local ray = camera:ViewportPointToRay(mousePos.X, mousePos.Y)

        local params = RaycastParams.new()
        params.FilterType = Enum.RaycastFilterType.Blacklist
        params.FilterDescendantsInstances = {plr.Character}
        
        result = workspace:Raycast(ray.Origin, ray.Direction * 10000, params)

        if result.Instance.Anchored == false and not grabbing then
            print(result.Instance.Name)
            grabpart = result.Instance
            grabbing = true
            
            attachment0 = Instance.new("Attachment")
            attachment0.Parent = grabpart
            attachment0.Name = "Attachment0"
            attachment0.Position = result.Position
            attachment0.Visible = true
            
            align = Instance.new("AlignPosition")
            align.Mode = Enum.PositionAlignmentMode.OneAttachment
            align.Attachment0 = attachment0
            align.Position = result.Position
            align.MaxForce = 50000
            align.Responsiveness = 4445
            align.Parent = grabpart
            align.Enabled = true

        end
        
        if grabbing then
            align.Position = result.Position
            --print(align.Position)
        end
    end
end)

tool.Deactivated:Connect(function()
    running = false
    grabbing = false
    grabpart = nil
    
    if align then
        align:Destroy()
        attachment0:Destroy()
    end
    print("stopped")
end)

wanton zephyr
silk mesa
#

that youre endlessly craeting new align positions

#

dont you

wanton zephyr
#

yea

#

im trying to create the physics gun from garry's mod

silk mesa
#

creating new align positions is not it

#

you need to create only one

#

and using that align position

#

you update it

#

try this

wanton zephyr
#

what do you mean by update ?

silk mesa
#

create only one align position

#

im assuming youre trying to create an align position for each object

#

but what youre doing is youre creating endless amounts of new align positions

wanton zephyr
#

im trying to make the grabbed object attracted by where the mouse is pointing at

#

so when it moves the align position is moved

silk mesa
#

yea but u keep creating new align positions here

if result.Instance.Anchored == false and not grabbing then
            print(result.Instance.Name)
            grabpart = result.Instance
            grabbing = true
            
            attachment0 = Instance.new("Attachment")
            attachment0.Parent = grabpart
            attachment0.Name = "Attachment0"
            attachment0.Position = result.Position
            attachment0.Visible = true
            
            align = Instance.new("AlignPosition")
            align.Mode = Enum.PositionAlignmentMode.OneAttachment
            align.Attachment0 = attachment0
            align.Position = result.Position
            align.MaxForce = 50000
            align.Responsiveness = 4445
            align.Parent = grabpart
            align.Enabled = true

        end```
finite pineBOT
#

studio** You are now Level 3! **studio

silk mesa
#

OK

silk mesa
#

while loop

#

and itll create only one

#

try that and let me know what happens

#

ill try to make an align position using this script meanwhile

#

yea i tried ur code and it has nothing bad with it

#

its just the while loop part im assuming

wanton zephyr
# silk mesa put this code outside of the

if it is before the while loop, it wont work cuz result is not defined yet, and if it is after the while loop, it will play at the end so it wont do anything cuz the attachment will be removed instantly

finite pineBOT
#

studio** You are now Level 9! **studio

silk mesa
#

adn then update it inside the loop

#
  • the attachment too
#

make them both outside the loop

#

or actually

#

just make a function that does an iteration of this while loop, create the attachment and the align position

#

run this function so it gets the result and sets the align position properties

#

and then just run this function in the loop as wlel

wanton zephyr
#

i dont think that is the problem because an align position and the attachment are created but even if it uses an align position outside a script it doesnt work (if i put it manually inside a part)

silk mesa
#

hm weird

#

but do the things i told to do as well

#

have you checked that

#

if the event actaully fires

wanton zephyr
#

i tried putting it outside the loop but it does the same thing for me . Idk cuz the align position worked on a past work so ima see what i did for it to work

silk mesa
#

just try to look at the grab object after you grab it and see whats inside it

#

idk why the align position does not work

#

but its probably because of the

#

grabobject itself

wanton zephyr
silk mesa
#

worked

wanton zephyr
silk mesa
#

yea

wanton zephyr
#

i may be dumb

#

but it could be because its a local script that i use

silk mesa
#

oh

wanton zephyr
#

i finally made it work

#

@silk mesa wanna see a video ?

silk mesa
#

sure

wanton zephyr
#

btw the reason was because it was inside a local script lol

silk mesa
#

oh wow 😭

wanton zephyr
#

sorry for taking your time(for a mistake that dumb)

silk mesa
#

its fine

wanton zephyr
#

kinda trash but working lol

silk mesa
wanton zephyr
#

thx !