Im trying to make a 2d pet system that spawns a pet next to a player
The pet isn’t appearing
I tried looking for solutions and tutorials but they are unhelpful.
local player = game.Players.LocalPlayer
local character = player.Character
local RunService = game:GetService("RunService")
local pet = Instance.new("Part")
pet.Name = "Pet"
pet.Size = Vector3.new(1, 1, 1)
pet.Parent = character
pet.Transparency = 1
local decal1 = Instance.new("Decal")
decal1.Parent = pet
decal1.Texture = "http://www.roblox.com/asset/?id=11598963797"
local decal2 = Instance.new("Decal")
decal2.Parent = pet
decal2.Texture = "http://www.roblox.com/asset/?id=11598963797"
local PetOffset = CFrame.new(-2,0,0) --offset of the pet from the character
local TweenOffset = CFrame.new(0,0,0) --offset to apply to the pet during the lerp
RunService.RenderStepped:Connect(function(dT)
local NewCF = character.HumanoidRootPart.CFrame * PetOffset --offset of hover eg cf(3,5,5)
pet.RootPart.CFrame = pet.RootPart.CFrame:Lerp(NewCF, .9) * TweenOffset
end)
while true do
wait(0.1)
end
There are a few things that could be causing your pet to not appear:
It’s possible that the pet is being created, but it’s just not visible because it’s transparency is set to 1. You can try setting the transparency to 0 or removing the line of code that sets the transparency to 1.
It’s also possible that the pet is being created, but it’s not being parented to the character correctly. You can try adding a print statement to check the value of pet.Parent to see if it’s being set correctly.
It’s possible that the issue is with the decals being applied to the pet. You can try removing the lines of code that create and apply the decals to the pet and see if that fixes the issue.
It’s possible that the issue is with the RenderStepped event connection. You can try moving the RunService.RenderStepped:Connect(function(dT) line of code outside of the while true do loop and see if that fixes the issue.
I hope this helps! Let me know if you have any other questions or if these suggestions don’t help fix the issue.
if you don’t like a response by a AI please ignore this
Unless you have a body mover to stabilize the pet, it will go all over the place so it should be anchored. Using tick() will give a more precise result. I was also unsure why you were doing .RootPart when your script does not have such instance. Edit the script accordingly to fit your current setup of the pet.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or workspace:WaitForChild(player.Name, 5)
-- add onto pet instance
pet.Anchored = true
local WaitTime = .05 -- seconds
local LastCheck = 0 -- time in seconds when last rendered/checked
RunService.RenderStepped:Connect(function(dT)
if tick() - LastCheck >= WaitTime then
LastCheck = tick()
local NewCF = character.HumanoidRootPart.CFrame * PetOffset --offset of hover eg cf(3,5,5)
pet.CFrame = pet.CFrame:Lerp(NewCF, .9) * TweenOffset
end
end)