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!
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