Part doesn't follow me

You can write your topic however you want, but you need to answer these questions:

  1. I want to make a part follow me using AlignPosition


As u can see it works only 2 or 3 seconds

--local script in StarterPlayerScripts
local PLAYERS = game:GetService("Players")
local PLAYER = PLAYERS.LocalPlayer
local CHARACTER = PLAYER.Character or PLAYER.CharacterAdded:Wait()
local MOVE_PART = workspace:WaitForChild("MovePart")
local RUN_SERVICE = game:GetService("RunService")
local HMRP = CHARACTER:WaitForChild("HumanoidRootPart")::Part
local REPLICATED_STORAGE = game:GetService("ReplicatedStorage")
local REMOTE_EVENT = REPLICATED_STORAGE:WaitForChild("MovePartEvent")

local ALIGN_POSSITION = MOVE_PART.AlignPosition

PLAYERS.PlayerAdded:Connect(function(player:Player)
	REMOTE_EVENT:FireServer(player)
end)

RUN_SERVICE.Stepped:Connect(function(dt)
	ALIGN_POSSITION.Position = HMRP.Position
end)
--ServerScript in ServerScriptService
local REPLICATED_STORAGE = game:GetService("ReplicatedStorage")
local REMOTE_EVENT = REPLICATED_STORAGE:WaitForChild("MovePartEvent")
REMOTE_EVENT.OnServerEvent:Connect(function(player)
	local MOVE_PART = workspace:WaitForChild("MovePart")
	MOVE_PART:SetNetworkOwner(player)
end)

Hmm, is the part Anchored ? Cause from what i know, SetNetworkOwner does not work on Anchored parts. And uh, WaitForChild yields until it finds the chosen object, that PlayerAdded Event.. i doubt if it works as expected as you are already in the game before setting that because of the WaitForChild functions you’re using, and stuff like PlayerAdded doesn’t work pretty well in a local script

I checked 5 times and switched and no it is not anchored

May i know if there is any error in the console ? (Cause console is not fully visible) What mode is align Position using ? 1 Attachment i assume?

ye i uze 1 attachment mode, and if i uze this script in server script it works, but in local script with ownership it works only 2-3 seconds

Can we see the properties of align position?

In addition to align position properties, what is the context you plan to use this? You can simply use two-attachment method in server script.

local Players = game:GetService("Players")
local part = game.Workspace.Part
local alignPosition = part.AlignPosition
local partAttach = part.Attachment

local function follow(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
	alignPosition.Attachment0 = partAttach
	alignPosition.Attachment1 = HumanoidRootPart:FindFirstChildWhichIsA("Attachment")
end

Players.PlayerAdded:Connect(follow)

I don’t want the server to load it so I use a local script

The reason that it stops following after a couple seconds is because the network owner is being set to back the server (while it was initially set to the player automatically by Roblox). This is because MOVE_PART:SetNetworkOwner(player) is never firing, as the PlayerAdded event in the player is not firing.

The simplest way to fix this, as I assume that the code is more for testing purposes at this point, is to get rid of the client side PlayerAdded event, and instead just have the client side code be

--local script in StarterPlayerScripts
local PLAYERS = game:GetService("Players")
local PLAYER = PLAYERS.LocalPlayer
local CHARACTER = PLAYER.Character or PLAYER.CharacterAdded:Wait()
local MOVE_PART = workspace:WaitForChild("MovePart")
local RUN_SERVICE = game:GetService("RunService")
local HMRP = CHARACTER:WaitForChild("HumanoidRootPart")::Part
local REPLICATED_STORAGE = game:GetService("ReplicatedStorage")
local REMOTE_EVENT = REPLICATED_STORAGE:WaitForChild("MovePartEvent")
local ALIGN_POSITION = MOVE_PART.AlignPosition

REMOTE_EVENT:FireServer(game.Players.LocalPlayer)

RUN_SERVICE.Stepped:Connect(function(dt)
	ALIGN_POSITION.Position = HMRP.Position
end)

Alternatively, have the PlayerAdded event be on the server.


Also, if the player dies, your script will break - you only get the player’s character once (at the start of the script), and the script wont refresh (as it is in StarterPlayerScripts, not StarterCharacterScripts). Either move the script to StarterPlayerScripts, or utilise Player.CharacterAdded

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.