GetPropertyChangedSignal not working on humanoidrootpart

so i have this code

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local missile = game.ReplicatedStorage.missile:Clone()
		missile.Parent = workspace
		missile.Position = Vector3.new(0,1000,0)
		local head:Part = char:WaitForChild("HumanoidRootPart")
		print("connecting")
		head:GetPropertyChangedSignal("Position"):Connect(function()
			print("fired")
			missile.CFrame = CFrame.lookAt(missile.Position,head.Position)
			print("changed")
		end)
	end)
end)

it runs fine until it reaches the head:GetPropertyChangedSignal("Position"):Connect(function()
part where it doesnt connect the function


you should change the position after connecting the event

your code
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local missile = game.ReplicatedStorage.missile:Clone()
		missile.Parent = workspace
		local head:Part = char:WaitForChild("HumanoidRootPart")
		print("connecting")
		head:GetPropertyChangedSignal("Position"):Connect(function()
			print("fired")
			missile.CFrame = CFrame.lookAt(missile.Position,head.Position)
			print("changed")
		end)
	end)
end)
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local missile = game.ReplicatedStorage.missile:Clone()
		missile.Parent = workspace
		local head:Part = char:WaitForChild("HumanoidRootPart")
		print("connecting")
		head:GetPropertyChangedSignal("Position"):Connect(function()
			print("fired")
			missile.CFrame = CFrame.lookAt(missile.Position,head.Position)
			print("changed")
		end)
		missile.Position = Vector3.new(0,1000,0) --only change
	end)
end)

@mhmdsndb3

what is the point tho it doesnt do anything(sorry for late response i accidently slept)

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local missile = game.ReplicatedStorage.missile:Clone()
		missile.Parent = workspace
		missile.Position = Vector3.new(0,1000,0)
		local head = char:WaitForChild("HumanoidRootPart")
		local lastPos = head.Position

		RunService.Heartbeat:Connect(function()
			if head.Position ~= lastPos then
				missile.CFrame = CFrame.lookAt(missile.Position, head.Position)
				lastPos = head.Position
			end
		end)
	end)
end)

i tried to avoid that method but ig i will just use it

btw what is the point of the last position varible

Ok then make a part like the humanoid root part and weld it make it unvisible and untouched and canquary false then name it like humanoid position detector then u can use the GetPropertyChangedSignal

1 Like

creating a new function every time the player character is added is the best way to make a memory leak, if the player dies 50 times, it will have 50 heartbeat function’s working,

literally your game gonna crash so hard.

Probally this is the best way for u:

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

--// Function's
local MoveDirectionTable = {}

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Humanoid = char:FindFirstChildWhichIsA("Humanoid")
		
		local missile = game.ReplicatedStorage.missile:Clone()
		missile.Parent = workspace
		missile.Position = Vector3.new(0,1000,0)
		
		local head = char:WaitForChild("HumanoidRootPart")
		local lastPos = head.Position
		
		if MoveDirectionTable[char] then
			MoveDirectionTable[char]:Disconnect()
			MoveDirectionTable[char] = nil
		end
		MoveDirectionTable[char] = Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
			if head.Position ~= lastPos then
				missile.CFrame = CFrame.lookAt(missile.Position, head.Position)
				lastPos = head.Position
			end
		end)
		
	end)
end)
1 Like

Oh ye this is perfect!! Ye good idea using the move direction is better!

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