Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
1
Answered by
haba_nero 386 Moderation Voter
4 years ago
Edited 4 years ago

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

0
Thanks! I will try out it out today. PrismaticFruits 842 — 4y
0
Nice answer layout by the way. PrismaticFruits 842 — 4y
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? PrismaticFruits 842 — 4y
0
Thank you :D haba_nero 386 — 4y
View all comments (7 more)
0
Um... You didn't answer my question. PrismaticFruits 842 — 4y
0
Ohh. Ok. Ask the question as a different question on scriptinghelpers haba_nero 386 — 4y
0
Thank you! haba_nero 386 — 4y
0
Oh wait nvm Ill just edit haba_nero 386 — 4y
0
Thanks! I will try the new version later on today. PrismaticFruits 842 — 4y
0
Wait so do I put the pets in Lighting or ServerStorage? PrismaticFruits 842 — 4y
0
ServerStorage haba_nero 386 — 4y
Ad

Answer this question