a funçao de desabilitar a gui livro para de funcionar quando o Jogador morre/renasce,…
- User
a funçao de desabilitar a gui livro para de funcionar quando o Jogador morre/renasce, tem como corrigir ? ; local Players = game:GetService("Players") local CollectionService = game:GetService("CollectionService") local RunService = game:GetService("RunService") local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid")
-- Evento remoto para comunicação cliente-servidor local RemoteEvent = ReplicatedStorage:WaitForChild("PlayerRotationEvent")
-- Variáveis de estado local currentSeat = nil local isSitting = false local isAlive = true local rotationActive = false -- Variável para controlar se a rotação está ativa
-- Variáveis para otimização do envio ao servidor local lastSendTime = 0 local sendInterval = 0.1 -- Intervalo mínimo entre envios ao servidor (em segundos) local lastYRotation = nil local rotationThreshold = 1 -- Envia a rotação somente se a diferença for maior que 1 grau
-- Variável para a conexão do evento RenderStepped local renderSteppedConnection
-- Buscar o botão "Stop" no PlayerGui local stopButton = player:WaitForChild("PlayerGui"):WaitForChild("Rotation"):WaitForChild("ImageButton") -- Buscar a GUI "Livro" local livroGui = player:WaitForChild("PlayerGui"):WaitForChild("Livro")
-- Função para atualizar a rotação do personagem local function updateCharacterRotation(deltaTime) if isSitting and isAlive then -- Obter a orientação da câmera local camera = workspace.CurrentCamera local cameraCF = camera.CFrame local _, yRotation, _ = cameraCF:ToEulerAnglesYXZ() local yRotationDegrees = math.deg(yRotation)
-- Correção para manter a rotação entre 0 e 360 graus yRotationDegrees = (yRotationDegrees + 360) % 360 -- Atualiza a rotação do personagem localmente em tempo real local rootPart = character:FindFirstChild("HumanoidRootPart") if rootPart then rootPart.CFrame = CFrame.new(rootPart.Position) * CFrame.Angles(0, math.rad(yRotationDegrees), 0) end -- Otimização: Envia apenas se o intervalo mínimo tiver passado e a diferença for significativa if os.clock() - lastSendTime >= sendInterval then if not lastYRotation or math.abs(yRotationDegrees - lastYRotation) >= rotationThreshold then -- Atualiza o último envio lastSendTime = os.clock() lastYRotation = yRotationDegrees -- Envia a rotação para o servidor RemoteEvent:FireServer(yRotationDegrees) end end endend
-- Função para detectar quando o jogador senta ou levanta local function onSeated(active, seatPart) if active then if CollectionService:HasTag(seatPart, "Rotation") then currentSeat = seatPart isSitting = true rotationActive = false -- Reseta para evitar inconsistências print("Jogador sentou em um assento de rotação.") else currentSeat = nil isSitting = false
-- Para a atualização de rotação se estiver ativa if renderSteppedConnection then renderSteppedConnection:Disconnect() renderSteppedConnection = nil end end else if isSitting then -- Envia rotação zero para resetar no servidor RemoteEvent:FireServer(0) currentSeat = nil isSitting = false rotationActive = false -- Removido: Habilita a GUI "Livro" ao sair do assento -- if livroGui then -- livroGui.Enabled = true -- end -- Resetar a orientação localmente local rootPart = character:FindFirstChild("HumanoidRootPart") if rootPart then rootPart.CFrame = CFrame.new(rootPart.Position) end -- Para a atualização de rotação if renderSteppedConnection then renderSteppedConnection:Disconnect() renderSteppedConnection = nil end end end - Assistant
Olá!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.