Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
8

[Sort of advanced CFrame issues] - How can I fix this? [closed]

Asked by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

So i'm trying to make a telekinesis tool, it uses BodyPosition to move the selected part around.. and it works but there's a problem. I have a conditional statement, where if the mouse's hit position is further away from the specified limit then the position shouldn't go any further away. Now the strangest this is that that bit works, but with the conditional then after it goes past the limit, the position automatically makes the X axis 0 for some unknown reason. I want to know how I can make the new position match up with the mouse's X axis, but still have the Z axis limit. Any ideas? Here's the bit of code for moving the part, all variables are defined and DistanceLimit is 100.

This is a localscript.

Move = (function (Mouse, Obj)
    local BodyPosition, CharTorso = Instance.new("BodyPosition",Obj), Plyr.Character.Torso; 
    BodyPosition.maxForce = Vector3.new(Obj.Size.X*5000,Obj.Size.Y*5000,Obj.Size.Z*5000)
    MovingObject = true
    while MovingObject do
        local mouseHit = Mouse.Hit.p
        --[[CONDITIONAL IS HERE]]--

        if (mouseHit - CharTorso.CFrame.p).magnitude <= DistanceLimit then
            pos = CFrame.new(mouseHit.X,5,mouseHit.Z)
        else
        --[[THIS IS WHAT'S MESSED UP]]--

        pos = (CFrame.new(mouseHit.X,5,0) + Vector3.new(CharTorso.CFrame * CFrame.new(0,0,DistanceLimit)))

        -------------------------------------------
        end
        BodyPosition.position = (pos).p
        wait(0.1)
    end
    MovingObject = false
    BodyPosition:Destroy()
end)
0
I don't fully understand your code and may not be much help, but if the X axis is the problem the try looking into bits where the X axis is mentioned, and I can only suggest printing out messages at each stage, to see if the part does actually go to the set position before it returns to 0 Mystdar 352 — 10y
1
Printing things out wouldn't do me any good. And what you said didn't make any sense. I'm wondering why mouse.Hit.p.X would return 0 when obviously 0 isn't the X axis.. And what I could do to fix it. Goulstem 8144 — 10y
0
Alright, I was just trying to help... Mystdar 352 — 10y

Closed as Not Constructive by Goulstem

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 8 years ago

--[[If I understand correctly, you're trying to send something to your mouse position?

Try this.. --]]

local player=game.Players.LocalPlayer local mouse=player:GetMouse() local torso = player.Character.Torso torso.CFrame = CFrame.new(mouse.Hit.p) + Vector3.new(0,3,0)

0
Thank you, but I solved this issue quite a long time ago(: Goulstem 8144 — 8y
Ad