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

How to make a part follow player on only a specified axis?

Asked by 2 years ago
Edited 2 years ago

So i want this part i named "straszak" spawn and follow player on one axis once it spawned.

local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
while wait(120) do
    if workspace:FindFirstChild("straszak") == nil then
        if math.random(1,2) == 1 then -- 50% chance
            local straszakclone = script.straszak:Clone()
            straszakclone.Parent = workspace
            coroutine.wrap(function()
                while wait() do
                    local vector, onScreen = workspace.CurrentCamera:WorldToViewportPoint(straszakclone.PrimaryPart.Position)
                    if onScreen == true then
                        print("onscreen") 
                    elseif onScreen == false then
                        print("offscreen")
                    end
                end
            end)()
            coroutine.wrap(function()
                while wait(5) do
                    straszakclone:SetPrimaryPartCFrame(char.HumanoidRootPart.CFrame*CFrame.new(Vector3.new(6,0,22.5))) -- it resets position every 5 seconds
                end
            end)()
            local CF = straszakclone.PrimaryPart.CFrame
            while wait() do
                straszakclone:SetPrimaryPartCFrame(CFrame.new()) -- i want it to follow player only on one axis
            end
        end
    end
end

here's a visual representation on what i want

Answer this question