How do I make a part follow player movements, so when the player walks to it won't come closer to the player

I want to make have a part don’t come closer to the player, so like it will follow any movements the player makes, when walking to the part it will stay in the same distance, and not closer to the player. Is this possible? I tried to change the position of the part, but I want it to always do this, like a sun but then a regular part (I’m not trying to get a sun, but a effect like when you try to walk to the sun so it won’t come closer to the player)

1 Like

If I understand correctly.

wait(5) --Wait for the player character to spawn
print("Waiting done!")

target = workspace:WaitForChild(game.Players:GetChildren()[1].Name) --Get the player that will be following
targetdelta = script.Parent.Position - target.HumanoidRootPart.Position --Get the initial position difference


game:GetService("RunService").Heartbeat:Connect(function()

    script.Parent.Position = target.HumanoidRootPart.Position + targetdelta --Set the part position 

end)

Result :

1 Like

Thank you, this is exactly what I meant, but it seems like that after the player respawns it stops working, any solution for this?

Modifying on to what @kimm20_neverdie said, you can do

wait(5) --Wait for the player character to spawn
print("Waiting done!")
local target
local targetDelta

game:GetService("RunService").Heartbeat:Connect(function()
    target = workspace:WaitForChild(game.Players:GetChildren()[1].Name) --Get the player that will be following
    targetdelta = script.Parent.Position - target.HumanoidRootPart.Position --Get the initial position difference
    script.Parent.Position = target.HumanoidRootPart.Position + targetdelta --Set the part position 

end)

This should keep updating the variables that even when the player respawns that it should still follow the player. This hopefully works, I’m on mobile and can’t confirm!

For some reason now it doesn’t work at all

Have you added orint statements? Does it work now?

What do you mean with orint statments? Do you mean print statments?

1 Like

Yes sorry typo! My bad!!!

So what is print statments? Can you give me a example? Do I need to put it in a script?

I’m saying like out a print statement inside of the run service event function to see if anything prints.

print(“This should run”)

That would output in the console if the acript ever gets to it

Where do I need to put "print(“This should run”)? At the first line?

Put it in the RunService function so like this:

    wait(5) --Wait for the player character to spawn
    print("Waiting done!")
    local target
    local targetDelta

    game:GetService("RunService").Heartbeat:Connect(function()
        print("This should run!")
        target = workspace:WaitForChild(game.Players:GetChildren()[1].Name) --Get the player that will be following
        targetdelta = script.Parent.Position - target.HumanoidRootPart.Position --Get the initial position difference
        script.Parent.Position = target.HumanoidRootPart.Position + targetdelta --Set the part position 

    end)

If you see this should run in the output that means it is running and the problem is something else

Also nevermind the other stuff I found the problem target is referencing the player:

But then you try to get HumanoidRootPart from the player which makes no sense:

But anyways I recommend using this code in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
    game:GetService("RunService").Heartbeat:Connect(function()
        local part = game.Workspace["PartName"].Position
        local targetdelta = part - player.Character.HumanoidRootPart.Position
        part.Position = targetdelta
    end)
end)

I wanna make multiple parts follow the player, do I need to copy this script and put the name of every single part I want to follow the player or is there a better way?

Well you can make multiple variables referencing the parts and then the deltaposition of the part (the player.Character.HumanoidRootPart.Position - part.Position)
Then set the parts position to that deltaposition

It’s not possible to make the parts from the model follow the player?

You could use a for loop to loop through the model to make the parts follow

K make sure to mark as solution

Doesn’t seem to work, I made a script, put it in ServerScriptService, is that good or do I need to do something else?

Do I need to put it inside a folder which is put inside ServerScriptService or that doesn’t matter?