modifique esse script para clonar um model chamado "Caderno" com os intes dentro dele,…
- User
modifique esse script para clonar um model chamado "Caderno" com os intes dentro dele, ao inves de clonar o mymesh : local ReplicatedStorage = game:GetService("ReplicatedStorage") local ServerStorage = game:GetService("ServerStorage") -- Onde o objeto original está armazenado local Players = game:GetService("Players")
-- RemoteEvent local CloneMeshEvent = ReplicatedStorage:FindFirstChild("CloneMeshEvent") if not CloneMeshEvent then CloneMeshEvent = Instance.new("RemoteEvent") CloneMeshEvent.Name = "CloneMeshEvent" CloneMeshEvent.Parent = ReplicatedStorage end
-- Objeto a ser clonado (deve estar em ServerStorage) local objectToClone = ServerStorage:WaitForChild("MyMesh") -- Certifique-se de que o objeto exista
-- Tabela para rastrear os objetos por jogador local playerObjects = {}
-- Tabela para rastrear as conexões por humanoide local humanoidConnections = {}
-- Função para clonar ou destruir o objeto local function onCloneMeshEvent(player, action) if action == "Clone" then -- Verifica se o jogador já tem um objeto if not playerObjects[player.UserId] then -- Obtém o humanoide do jogador e verifica se está sentado em 'Sala_Aula' local character = player.Character local humanoid = character and character:FindFirstChildOfClass("Humanoid") if humanoid then local seatPart = humanoid.SeatPart if seatPart and seatPart.Name == "Sala_Aula" then -- Conecta o evento para monitorar quando o jogador sair do assento if not humanoidConnections[humanoid] then local connection connection = humanoid:GetPropertyChangedSignal("SeatPart"):Connect(function() local currentSeat = humanoid.SeatPart if not currentSeat or currentSeat.Name ~= "Sala_Aula" then -- Jogador saiu do assento 'Sala_Aula', destruir o objeto local obj = playerObjects[player.UserId] if obj then obj:Destroy() playerObjects[player.UserId] = nil end -- Desconecta o evento if humanoidConnections[humanoid] then humanoidConnections[humanoid]:Disconnect() humanoidConnections[humanoid] = nil end end end) humanoidConnections[humanoid] = connection end
-- Clona o objeto local clonedObject = objectToClone:Clone() clonedObject.Anchored = true -- Usa a posição do Seat local seatCFrame = seatPart.CFrame -- Desloca 5 studs no eixo X e 5 studs no eixo Y a partir do seat local offset = CFrame.new(0, 3, -3) clonedObject.CFrame = seatCFrame * offset clonedObject.Parent = workspace -- Armazena o objeto clonado playerObjects[player.UserId] = clonedObject else -- Opcional: Enviar uma mensagem ao jogador indicando que ele não está em 'Sala_Aula' print("Jogador não está sentado em 'Sala_Aula'. Não é possível clonar o objeto.") end end end elseif action == "Destroy" then -- Verifica se o jogador tem um objeto local obj = playerObjects[player.UserId] if obj then obj:Destroy() playerObjects[player.UserId] = nil end -- Desconecta o evento de monitoramento do assento, se existir local character = player.Character local humanoid = character and character:FindFirstChildOfClass("Humanoid") if humanoid and humanoidConnections[humanoid] then humanoidConnections[humanoid]:Disconnect() humanoidConnections[humanoid] = nil end end - Assistant