-
Im creating a pet system where you can equip and unequip pets.
-
The issue is the remote event is firing to many times and messing up the game/
-
I looked on the devforum but couldnt figure out how to fix it.
My script is down below
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Info = script.Parent.Parent.Parent.Information
for i, v in pairs(ReplicatedStorage.Pets:GetChildren()) do
local PetFrame = script.Parent.Parent["Pet Frame"]:Clone()
PetFrame.Parent = script.Parent
local Rarity = v:FindFirstChild("Rarity")
local petName = v.Name
print(petName)
PetFrame.Visible = true
PetFrame.Name = petName
local Module3D = require(game.ReplicatedStorage:WaitForChild("Module3D"))
local Model3D = Module3D:Attach3D(PetFrame, v:Clone())
Model3D:SetDepthMultiplier(1.2)
Model3D.Camera.FieldOfView = 5
Model3D.Visible = true
game:GetService("RunService").RenderStepped:Connect(function()
Model3D:SetCFrame(CFrame.Angles(0, tick() % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
end)
PetFrame.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
Info.ItemName.Text = petName
Info.Description.Text = tostring("Rarity: " .. Rarity.Value)
local Pet = game.ReplicatedStorage.Pets:FindFirstChild(petName):Clone()
local Model3d = Module3D:Attach3D(Info.ImageContainer.ViewportFrame, Pet)
Model3d:SetDepthMultiplier(1.2)
Model3d.Camera.FieldOfView = 5
Model3d.Visible = true
game:GetService("RunService").RenderStepped:Connect(function()
Model3d:SetCFrame(CFrame.Angles(0, tick() % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
end)
end
end)
end
Info.EquipButton.MouseButton1Click:Connect(function()
ReplicatedStorage.Equip:FireServer(Info.ItemName.Text)
end)
Any Help Is Good as im very stuck.