AlvinBlox Pet System

local player = game.Players.LocalPlayer
local Dog = game.ReplicatedStorage.Pets.Dog
local leaderstats = player:WaitForChild("leaderstats")
local template = script:WaitForChild("ImageButton")
local scrollingFrame = script.Parent.Parent.Parent.Parent:WaitForChild("Inventory"):WaitForChild("InventoryFrame"):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"
			v.TextColor3 = Color3.fromRGB(255,0,0)
		end
	end
	template.Equipped.Text = "EQUIPPED"
	template.Equipped.TextColor3 = Color3.fromRGB(0,255,0)
end
local function addToFrame(pet)
	local newTemplate = template:Clone()
	newTemplate.Parent = scrollingFrame
	newTemplate.Name = "Dog"
	newTemplate.PetName.Text = "Dog"
	local newPet = Dog: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"
			newTemplate.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
		else
			game.ReplicatedStorage.EquipPet:FireServer(pet.Name)
			setTemplateEquipped(newTemplate)
		end
	end)
	
end
script.Parent.MouseButton1Click:Connect(function(player,Dog)
	if leaderstats.Cash.Value >= 500 then
		leaderstats.Cash.Value = leaderstats.Cash.Value - 500
		addToFrame(Dog)
	end
end)

This is alvinbloxā€™s pet system video 2 and thereā€™s an error where it says Players.U_npluggedDev.PlayerGui.ScreenGui.Frame.Dog.LocalScript:34: attempt to index nil with ā€˜Nameā€™

Could you send line #34? I canā€™t see the line numbers

Nvm, I found the solution. Thanks for the response though.

Remove the ā€œDogā€ parameter from the mouseclick function.
Edit: Oh, you already found the solution. I wrote this before I saw the comment.

would you please share what you did to fix this problem so others can benefit from your discovery.

2 Likes

Send the solution here, so when new people come they get the solution

I was trying to not make eggs, and use a GUI button where you click it and you get the same pet 100% of the time, but I was adding Dog parameter sometimes and pet parameter the other times. I never sent the pet parameter, and I was trying to fire a remote event from client, to the server, back to the same client.

1 Like