so yeah the error is this : 14:07:27.753 - Players.m6xw.PlayerGui.Inventory.GuiClient:26: attempt to index nil with 'Name'

and the script (that i tried to fix many time)

local tweenSercice = game:GetService("TweenService")

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(template)
	
	for i, v in pairs(scrollingFrame:GetChildren()) do
		if v:FindFirstChild("Equipped") then
			v.Equipped.Text = "Unequipped"
		end
	end
	
	template.Equipped.Text = "Equipped"
	
end

local function addToFrame(pet)
	
	local newTemplate = template:Clone()
	newTemplate.Name = 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 == "Equipped" then
			game.ReplicatedStorage.UnequipPet:FireServer()
			newTemplate.Equipped.Text = "Unequipped"
		else
			game.ReplicatedStorage.EquipPet:FireServer()
			setTemplateEquipped(newTemplate)
		end
	end)
	
end

game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function(pet)
	
	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
	
	petClone.SetPrimaryPartCFrame( CFrame.new(studio.Egg.Position,studio.CamPart.Position) )
	petClone.Parent = studio
	
	local tweenInfo = TweenInfo.new(
		2,
		Enum.EasingStyle.Bounce,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	
	local tween = tweenSercice: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)
	
	camera.CameraType = Enum.CameraType.Custom
	studio.Egg.Transparency = 0
	studio.Egg.Size = Vector3.new(4.099, 5.335, 4.091)
	petClone:Destroy()
	
end)

2 comments

0

Can you tell me more about this script?

0

Looks like your game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect() event isnt passing the desired Pet for your script to grab its name. i would check the other script(s) that talk to that event to see whats going on..