Pet Scripting Error?

Here is some code that I’m confused about. I don’t know exactly why it isn’t working. It worked before I was deciding to leave it in ServerStorage intending for a use of others later, once this issue is fixed.

There are no errors at all for some reason, but it’s not working.

local cloned = game.ServerStorage["Meshes/ship2 (2)"]:Clone()
cloned.Name = "Ship"
cloned.Parent=workspace

local PetPos = Instance.new("BodyPosition", cloned)
local PetGyro = Instance.new("BodyGyro", cloned)
PetGyro.MaxTorque = Vector3.new(400000,400000,400000)
local Owner = 'Derpee_Kirbee'

while (1) do 
	wait()
	local OwnerObj = workspace:WaitForChild(Owner)
	local OwnerPos = OwnerObj.HumanoidRootPart.Position
	local StopAt = ((OwnerPos - cloned.Position).magnitude - 5) * 1000
	PetPos.P = StopAt
	PetPos.Position = OwnerPos + Vector3.new (0,10,0)
	PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame
	
end

Is it the fact that something is running too early?

you could look at your pet following system and have an idea there

@FerbZides The following system was working before I changed the location, don’t think that’s the issue.

I suggest changing the OwnerObj Value to:
game.Players:FindFirstChild(Owner).Character

Are you using a Local Script or a Server Script?

@IEnforce_Lawz I’m using a Server Script

Try putting prints in between each line in the loop

then check your output for if it stops printing

@IEnforce_Lawz Do you know a solution? I don’t see how to fix it.

1

2

16:50:01.876 - ServerScriptService.PetScript:15: attempt to index nil with ‘HumanoidRootPart’

Well that got somewhere I’ll try to figure it out

I did this:

while (1) do 
	wait()
	print("1")
	local OwnerObj = game.Players:FindFirstChild(Owner).Character
	print("2")
	local OwnerPos = OwnerObj.HumanoidRootPart.Position
	print("3")
	local StopAt = ((OwnerPos - cloned.Position).magnitude - 5) * 1000
	print("4")
	PetPos.P = StopAt
	print("5")
	PetPos.Position = OwnerPos + Vector3.new (0,10,0)
	print("6")
	PetGyro.CFrame = OwnerObj.HumanoidRootPart.CFrame
	print("7")
local cloned = game.ServerStorage["Meshes/ship2 (2)"]:Clone()
cloned.Name = "Ship"
cloned.Parent=workspace

local PetPos = Instance.new("BodyPosition", cloned)
local PetGyro = Instance.new("BodyGyro", cloned)
PetGyro.MaxTorque = Vector3.new(400000,400000,400000)
local Owner = 'Derpee_Kirbee'

while true do 
	wait(1)
	local OwnerPlayer = game.Players:FindFirstChild(Owner)
	if OwnerPlayer ~= nil then
		local OwnerCharacter = OwnerPlayer.Character or OwnerPlayer.CharacterAdded:Wait()
		if OwnerCharacter ~= nil then
			local OwnerPos = OwnerCharacter.HumanoidRootPart.Position
			local StopAt = ((OwnerPos - cloned.Position).magnitude - 5) * 1000
			PetPos.P = StopAt
			PetPos.Position = OwnerPos + Vector3.new(0,10,0)
			PetGyro.CFrame = OwnerCharacter.HumanoidRootPart.CFrame
		end
	end
end

@kylerzong that script didn’t work I copied all of it

Errors?

Upload the roblox studio file

There’s no file. There were no errors displayed, but it didn’t work.

Can’t help you much without any errors or a studio file, you can make a file and upload it

try this…

local cloned = game.ServerStorage["Meshes/ship2 (2)"]:Clone()
cloned.Name = "Ship"
cloned.Parent=workspace

local PetPos = Instance.new("BodyPosition", cloned)
local PetGyro = Instance.new("BodyGyro", cloned)
PetGyro.MaxTorque = Vector3.new(400000,400000,400000)
local Owner = 'Derpee_Kirbee'

while true do 
	wait(1)
	local OwnerPlayer = game.Players:FindFirstChild(Owner)
	if OwnerPlayer ~= nil then
		local OwnerCharacter = OwnerPlayer.Character or OwnerPlayer.CharacterAdded:Wait()
		if OwnerCharacter ~= nil then
			local OwnerPos = OwnerCharacter.HumanoidRootPart.Position
			local StopAt = ((OwnerPos - cloned.Position).magnitude - 5) * 1000
			PetPos.P = StopAt
			PetPos.Position = OwnerPos + Vector3.new(0,10,0)
			PetGyro.CFrame = OwnerCharacter.HumanoidRootPart.CFrame
		else
			print("OwnerCharacter is nil")
		end
	else
		print("OwnerPlayer is nil")
	end
end

game.rbxl (225.2 KB)

New script you just posted didn’t work

I set transparency to 1 I forgot thanks I think it works now I’ll just change that in the code.

1 Like

image

Yeah…

Okay fixed thanks It work(30 c)

If @kylerzong has solved your problem, it would be nice of you to mark his response as the “Solution”. You can locate that button directly under his response.

1 Like