#Align position not working
1 messages · Page 1 of 1 (latest)
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
is the part anchored or no
the one which has attachment0 in it
It is not anchored
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)
idk but its annoying , i gave you the code in case
you do knmow
that youre endlessly craeting new align positions
dont you
creating new align positions is not it
you need to create only one
and using that align position
you update it
try this
what do you mean by update ?
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
im trying to make the grabbed object attracted by where the mouse is pointing at
so when it moves the align position is moved
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```
** You are now Level 3! **
OK
put this code outside of the
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
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
** You are now Level 9! **
just make the align position
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
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)
hm weird
but do the things i told to do as well
have you checked that
if the event actaully fires
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
ik ik but you keeping it in the loop just creates alot of align positions that jus
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
i alr did that and it has the align position and the attachment
cu zi tried this part of the code on my side and it worker
worked
the object moved ?
yea
oh
sure
btw the reason was because it was inside a local script lol
oh wow 😭
sorry for taking your time(for a mistake that dumb)
its fine
its actually not bad at all i like it
thx !