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)
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
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,
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)