View difference between Paste ID: nz91ZuND and H1f8qXPD
SHOW: | | - or go back to the newest paste.
1
local runService = game:GetService("RunService")
2
local replicatedStorage = game:WaitForChild("ReplicatedStorage")
3
local replicatedFirst = game:WaitForChild("ReplicatedFirst")
4
5
6
local remotes = replicatedStorage:WaitForChild("Remotes")
7
8
9
local pets = replicatedFirst:WaitForChild("Pets")
10
11
12
local tweenService = game:GetService("TweenService")
13
14
15
local player = game.Players.LocalPlayer
16
local playerGui = player:WaitForChild("PlayerGui")
17
local screenGui = playerGui:WaitForChild("ScreenGui")
18
local center = screenGui:WaitForChild("Center")
19
local petInventory = center:WaitForChild("PetInventory")
20
local scrollingFrame = petInventory:WaitForChild("ScrollingFrame")
21
local template = scrollingFrame:WaitForChild("Template")
22
23
24
local module3D = require(replicatedStorage:WaitForChild("Module3D"))
25
26
27
local maxSelectedPets = 10
28
29
30
local selectedPets = 0
31
32
33
local function onTemplateClick(clickedTemplate, id)
34
35
36
    local equipped = clickedTemplate.Equipped.Value
37
38
39
    if not equipped and selectedPets < maxSelectedPets then
40
        clickedTemplate.Equipped.Value = true
41
        tweenService:Create(
42
            clickedTemplate,
43
            TweenInfo.new(0.4),
44
            {
45
                BackgroundColor3 = Color3.fromRGB(96,235,36)
46
            }
47
        ):Play()
48
        selectedPets = selectedPets + 1
49
        remotes.EquipPet:FireServer(clickedTemplate.Name, id)
50
    elseif equipped then
51
        clickedTemplate.Equipped.Value = false
52
        tweenService:Create(clickedTemplate,
53
            TweenInfo.new(0.4),
54
            {
55
                BackgroundColor3 = Color3.fromRGB(46,189,255)
56
            }
57
        ):Play()
58
        selectedPets = selectedPets - 1
59
        remotes.UnequipPet:FireServer(clickedTemplate.Name, id)
60
    end
61
end
62
63
64
local function createTemplate(petName, id)
65
    local newTemplate = template:Clone()
66
    newTemplate.Name = petName
67
    newTemplate.Visible = true
68
    newTemplate.Parent = scrollingFrame
69
70
71
    local petModel3D = module3D:Attach3D(
72
        newTemplate:WaitForChild("Viewport"),
73
        pets:WaitForChild(petName):Clone())
74
   
75
    petModel3D:SetDepthMultiplier(2)
76
    petModel3D.CurrentCamera.FieldOfView = 5
77
    petModel3D.Visible = true
78
79
80
    runService.RenderStepped:Connect(function()
81
        petModel3D:SetCFrame(
82
            CFrame.Angles(
83
                0,
84
                tick() % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
85
    end)
86
87
88
    newTemplate.MouseButton1Click:Connect(function()
89
        onTemplateClick(newTemplate, id)
90
    end)
91
end
92
93
94
remotes:WaitForChild("CreateTemplate").OnClientEvent:Connect(function(name, id)
95
    createTemplate(name, id)
96
end)