Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Would I Make Pets That You Can Unequip and Equip?

I am making a game where you can buy and have pets that follow their owner around. I am new to scripting so this is all I could make so far (inside the pet):

while true do
     wait(3)
     script.Parent.Position = Character.HumanoidRootPart.Position - Vector3.new(3,3,0) --I don't even know how to get the character of the owner
end

If someone could help me In would really appreciate that. Thanks in advance!

1 answer

✓ Accepted answer

Start with this! I can make a GUI button that when clicked, and you have 10 money, will give you a pet! Just follow these steps!

1

Make a RemoteEvent in ReplicatedStorage called Pets. Move the pet to ServerStorage and call it "Pet1" 2 Put this script inside the pet and disable it:

while true do
     wait(0.1)
     script.Parent.Position = script.Parent.Parent.Position - Vector3.new(3,3,0) 
end

2

Put this LocalScript inside a GUI button

script.Parent.MouseButton1Click:Connect(function()
	local Player = game.Players.LocalPlayer
	if Player.leaderstats:FindFirstChild("Money").Value >= 10 then
		game.ReplicatedStorage:FindFirstChild("Pets"):FireServer(Player.Name,"Pet1")
	end
end)

3

Put this Script in ServerScriptService

game.ReplicatedStorage:FindFirstChild("Pets").OnServerEvent:Connect(function(player,pet)
	local Pets = game.ServerStorage:FindFirstChild(pet)
	if Pets then
		local Clone = Pets:Clone()
		Clone.Parent = 		game.Workspace:FindFirstChild(player):FindFirstChild("HumanoidRootPart")
		Clone:FindFirstChild("Script").Disabled = false
	end
end)

Even if this does not work, it should give you some ideas! If you have any questions, comment below!

Best,

TheLastHabanero

EDIT

To save pets, you need to make a table:

local DS = game:GetService("DatastoreService")
local Store = DS:GetDataStore("Pets")
game.Players.PlayerAdded:Connect(function(plr)
	local Stats
	local success,fail = pcall funtion()
		Stats = Store:GetAsync(plr.UserId.."-Pets")
	end	
	if success then
		for i, stat in pairs(Stats) do
			local Clone = game.ServerStorage:FindFirstChild(stat)
			if Clone then
				Clone:Clone().Parent = plr.Character:FindFirstChild("HumanoidRootPart")
			end
		end	
	else

	end
end
game.Players.PlayerRemoving:Connect(function(plr)
	local Pets = {}
	local Childs = plr.Character:FindFirstChild("HumanoidRootPart"):GetChildren()
	if #Childs >= 1 then
		for i,child in pairs(Childs) do
			table.insert(child)
		end	
	end
	pcall function()
		Store:SetAsync(plr.UserId.."-Pets",Pets)
	end
end

Just make sure to make all the pets in Lighting and it should work! Unfortunately, unequipping and equipping will require some time to make, so you will have to wait. I'm sorry. But hey! Here's the save part! Have fun!

TheLastHabanero

11 comments

0

Thanks! I will try out it out today.

0

Nice answer layout by the way.

0

I hate to be "requesting stuff" but how would I make them be able to unequip/equip owned pets and how to make their owned pets save?

0

Thank you :D

0

Um... You didn't answer my question.

0

Ohh. Ok. Ask the question as a different question on scriptinghelpers

0

Thank you!

0

Oh wait nvm Ill just edit

0

Thanks! I will try the new version later on today.

0

Wait so do I put the pets in Lighting or ServerStorage?

0

ServerStorage

This discussion is preserved as it was. New answers, comments, and votes are closed.