• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


29 Nov, 2024

Updated at 14 Dec, 2024

What folder do I put this in?

Hi everyone

I have a script that’s supposed to make a pet that follows the player around wherever they go. I’ve been doing this, and I do in fact have a working script. I was going to ask, however, into what folder I should put it in so that it works.

local object = workspace.follow -- insert the object you want to follow the player here
local player = game.Players.LocalPlayer
local speed = 20 -- set the speed at which the object will follow the player

while true do
	local playerPos = player.Character.HumanoidRootPart.Position
	local objectPos = object.Position
	local direction = (playerPos - objectPos).Unit
	local distance = (playerPos - objectPos).Magnitude

	if distance > 5 then -- only moves if distance is greater than 0.1
		object.CFrame = object.CFrame + direction * speed * math.min(distance, 1/60)
	 
	end
	if distance > 10 then 
		object.CFrame = object.CFrame + direction * 30 * math.min(distance, 1/60)
	end

	wait()
end

Thanks!
-mythyx

2 posts - 2 participants

Read full topic