Here is the script. I have no idea i have checked all of my scripts and my explorer and nothing seemed to work. Here is the script with the problem:
--The error is on line 83
local function equipPet(player,pet)
local character = player.Character
if pet ~= nil and character ~= nil then
if character:FindFirstChild(player.Name.."'s Pet") then character[player.Name.."'s Pet"]:Destroy() end
if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
end
pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
pet.Name = player.Name.."'s Pet"
local modelSize = pet.PrimaryPart.Size
local attachmentCharacter = Instance.new("Attachment")
attachmentCharacter.Visible = false
attachmentCharacter.Name = "attachmentCharacter"
attachmentCharacter.Parent = character.HumanoidRootPart
attachmentCharacter.Position = Vector3.new(1,1,0) + modelSize
local attachmentPet = Instance.new("Attachment")
attachmentPet.Visible = false
attachmentPet.Parent = pet.PrimaryPart
local alignPosition = Instance.new("AlignPosition")
alignPosition.MaxForce = 25000
alignPosition.Attachment0 = attachmentPet
alignPosition.Attachment1 = attachmentCharacter
alignPosition.Responsiveness = 25
alignPosition.Parent = pet
local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.MaxTorque = 25000
alignOrientation.Attachment0 = attachmentPet
alignOrientation.Attachment1 = attachmentCharacter
alignOrientation.Responsiveness = 25
alignOrientation.Parent = pet
pet.Parent = character
end
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 10000
cash.Parent = leaderstats
local inventory = Instance.new("Folder")
inventory.Name = "Inventory"
inventory.Parent = player
local equippedPet = Instance.new("StringValue")
equippedPet.Name = "EquippedPet"
equippedPet.Parent = player
player.CharacterAdded:Connect(function(char)
if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
end
end)
equippedPet.Changed:Connect(function()
if equippedPet.Value ~= nil then
if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
end
end
end)
end)
game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName)
local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
if pet and player.PetInventory:FindFirstChild(petName)then -- this is the error :(
player.EquippedPet.Value = petName
end
end)
game.ReplicatedStorage.UnequipPet.OnServerEvent:Connect(function(player)
player.EquippedPet.Value = ""
if player.Character:FindFirstChild(player.Name.."'s Pet") then
player.Character[player.Name.."'s Pet"]:Destroy()
end
if player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
end
end)
This is my main script, here is the invertory handler for the main script:
local TweenService = game:GetService("TweenService")
Button = script.Parent.Button
local camera = game.Workspace.Camera
local studio = game.Workspace.Studio
local template = script:WaitForChild("Template")
local scrollingFrame = script.Parent:WaitForChild("Pets"):WaitForChild("ScrollingFrame")
local buttonConnections = {}
local function setTemplateEquipped()
for i, v in pairs(scrollingFrame:GetChildren()) do
if v:FindFirstChild("Equipped") then
v.Equipped.Text = "Equip"
v.Equipped.Roundify.ImageColor3 = Color3.fromRGB(0,255,0)
end
end
template.Equipped.Text = "Unequip"
template.Equipped.Roundify.ImageColor3 = Color3.fromRGB(65,65,65)
end
local function addToFrame(pet)
local newTemplate = template:Clone()
newTemplate.Name = pet.Name
newTemplate.PetName.Text = pet.Name
newTemplate.Parent = scrollingFrame
local newPet = pet:Clone()
newPet.Parent = newTemplate.ViewportFrame
local camera = Instance.new("Camera")
camera.CFrame = CFrame.new(newPet.PrimaryPart.Position + (newPet.PrimaryPart.CFrame.lookVector * 3),newPet.PrimaryPart.Position)
camera.Parent = newTemplate.ViewportFrame
newTemplate.ViewportFrame.CurrentCamera = camera
buttonConnections[#buttonConnections+1] = newTemplate.MouseButton1Click:Connect(function()
if newTemplate.Equipped.Text == "Unequip" then
game.ReplicatedStorage.UnequipPet:FireServer()
newTemplate.Equipped.Text = "Equip"
newTemplate.Equipped.Roundify.ImageColor3 = Color3.fromRGB(0,255,0)
else
game.ReplicatedStorage.EquipPet:FireServer(pet.Name)
setTemplateEquipped(newTemplate)
end
end)
end
game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function(pet)
Button.Visible = false
addToFrame(pet)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = studio.CamPart.CFrame
wait(1.5)
for i = 1, 50, 1 do
studio.Egg.Size = studio.Egg.Size + Vector3.new(0.1,0.1,0.1)
wait(0.01)
end
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 10
explosion.BlastPressure = 0
explosion.Position = studio.Egg.Position
explosion.ExplosionType = Enum.ExplosionType.NoCraters
explosion.DestroyJointRadiusPercent = 0
explosion.Parent = studio.Egg
studio.Egg.Transparency = 1
local petClone = pet:Clone()
for i , v in pairs(petClone:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = true
end
end
for i , v in pairs(studio.Confetti:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = true
v.Rate = 5
v.Drag = -1
end
end
petClone:SetPrimaryPartCFrame (CFrame.new(studio.Egg.Position,studio.CamPart.Position) )
petClone.Parent = studio
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Circular,
Enum.EasingDirection.InOut,
0,
false,
0
)
local tween = TweenService:Create(camera, tweenInfo, {CFrame = CFrame.new(petClone.PrimaryPart.Position + (petClone.PrimaryPart.CFrame.LookVector * 5) + Vector3.new(0,0.75,0),petClone.PrimaryPart.Position) } )
tween:Play()
wait(5)
for i , v in pairs(studio.Confetti:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = false
end
end
camera.CameraType = Enum.CameraType.Custom
studio.Egg.Transparency = 0
studio.Egg.Size = Vector3.new(5.904, 6.613, 5.904)
petClone:Destroy()
Button.Visible = true
end)
game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName)
local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
if pet and player.PetInventory:FindFirstChild(petName)then
player.EquippedPet.Value = petName
end
end)
Thank you for reading.
