-- วางโค้ดนี้ใน LocalScript ภายใน StarterPlayerScripts
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
-- === [ ตั้งค่าการใช้งาน ] ===
local TOGGLE_KEY = Enum.KeyCode.G -- กดปุ่ม G เพื่อเปิด/ปิด (เปลี่ยนปุ่มได้)
-- =========================
local isInvisible = false
local originalTransparencies = {}
local originalHealthChangedConnection = nil
-- ฟังก์ชันทำให้อวัยวะและเสื้อผ้า ล่องหน/ปรากฏตัว
local function setTransparency(char, transparencyValue)
for _, part in ipairs(char:GetDescendants()) do
-- ล่องหนพวกชิ้นส่วนร่างกาย
if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then
if transparencyValue == 1 then
-- บันทึกค่าความใสเดิมไว้ก่อนซ่อน
originalTransparencies[part] = part.Transparency
part.Transparency = 1
else
-- คืนค่าความใสเดิม
part.Transparency = originalTransparencies[part] or 0
end
-- ซ่อนพวกใบหน้า (Decal)
elseif part:IsA("Decal") then
if transparencyValue == 1 then
originalTransparencies[part] = part.Transparency
part.Transparency = 1
else
part.Transparency = originalTransparencies[part] or 0
end
end
end
end
-- ฟังก์ชันเปิด/ปิดโหมด ล่องหน + ยิงไม่เข้า
local function toggleInvisibility()
character = localPlayer.Character
if not character or not character:FindFirstChild("Humanoid") then return end
local humanoid = character.Humanoid
isInvisible = not isInvisible
if isInvisible then
-- 1. สั่งล่องหน
setTransparency(character, 1)
-- ซ่อนชื่อบนหัว
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
-- 2. ระบบอมตะ (ยิงไม่โดน / เลือดไม่ลด)
-- บล็อกไม่ให้เลือดลดเมื่อโดนโจมตี
originalHealthChangedConnection = humanoid.HealthChanged:Connect(function(health)
if health < humanoid.MaxHealth and isInvisible then
humanoid.Health = humanoid.MaxHealth -- เติมเลือดเต็มทันทีเมื่อโดนยิง
end
end)
humanoid.MaxHealth = math.huge -- ตั้งค่าเลือดเป็นอินฟินิตี้ชั่วคราว
humanoid.Health = math.huge
print("เปิดใช้งาน: ล่องหน + อมตะ")
else
-- 1. ยกเลิกการล่องหน (กลับมาเป็นปกติ)
setTransparency(character, 0)
originalTransparencies = {}
-- เปิดให้เห็นชื่อบนหัวเหมือนเดิม
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
-- 2. ยกเลิกโหมดอมตะ
if originalHealthChangedConnection then
originalHealthChangedConnection:Disconnect()
end
humanoid.MaxHealth = 100
humanoid.Health = 100
print("ปิดใช้งาน: กลับสู่สถานะปกติ")
end
end
-- ตรวจสอบการกดปุ่ม G
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == TOGGLE_KEY then
toggleInvisibility()
end
end)
-- รีเซ็ตค่าหากตัวละครตายแล้วเกิดใหม่
localPlayer.CharacterAdded:Connect(function(newChar)
character = newChar
isInvisible = false
if originalHealthChangedConnection then
originalHealthChangedConnection:Disconnect()
end
end)
LocalScript ภายใน StarterPlayerScripts
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local localPlayer = Players.LocalPlayer
local camera = Workspace.CurrentCamera
local isTargeting = false
local targetCharacter = nil
local runConnection = nil
-- ฟังก์ชันค้นหาผู้เล่นที่ใกล้ที่สุด
local function getClosestPlayer()
local closestPlayer = nil
local shortestDistance = MAX_DISTANCE
local localCharacter = localPlayer.Character
if not localCharacter or not localCharacter:FindFirstChild("HumanoidRootPart") then
return nil
end
local myPos = localCharacter.HumanoidRootPart.Position
for _, player in ipairs(Players:GetPlayers()) do
if player ~= localPlayer then
local char = player.Character
-- ตรวจสอบว่าผู้เล่นคนนั้นยังมีชีวิตอยู่และมี "Head"
if char and char:FindFirstChild("Head") and char:FindFirstChild("Humanoid") and char.Humanoid.Health > 0 then
local targetHead = char.Head
local distance = (myPos - targetHead.Position).Magnitude
if distance < shortestDistance then
shortestDistance = distance
closestPlayer = char
end
end
end
end
return closestPlayer
end
-- ฟังก์ชันอัปเดตมุมกล้องให้หันไปที่หัวเป้าหมาย
local function updateCamera()
if not isTargeting or not targetCharacter or not targetCharacter:FindFirstChild("Head") or (targetCharacter:FindFirstChild("Humanoid") and targetCharacter.Humanoid.Health <= 0) then
-- ถ้าเป้าหมายตาย หรือหายไป ให้ยกเลิกการล็อค
isTargeting = false
targetCharacter = nil
if runConnection then
runConnection:Disconnect()
end
return
end
-- หันกล้องไปที่ตำแหน่งของ Head ของเป้าหมาย
local headPos = targetCharacter.Head.Position
camera.CFrame = CFrame.new(camera.CFrame.Position, headPos)
end
-- ตรวจสอบการกดปุ่ม
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end -- ป้องกันการทำงานตอนพิมพ์แชท
if input.KeyCode == LOCK_KEY then
if isTargeting then
-- ถ้ากำลังล็อคอยู่ ให้ปลดล็อค
isTargeting = false
targetCharacter = nil
if runConnection then
runConnection:Disconnect()
end
else
-- ถ้ายังไม่ได้ล็อค ให้หาเป้าหมายที่ใกล้ที่สุด
local closest = getClosestPlayer()
if closest then
targetCharacter = closest
isTargeting = true
-- สั่งให้กล้องอัปเดตตามเป้าหมายทุกเฟรม
runConnection = RunService.RenderStepped:Connect(updateCamera)
end
end
end
Comments
-- วางโค้ดนี้ใน LocalScript ภายใน StarterPlayerScripts local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService")
local localPlayer = Players.LocalPlayer local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
-- === [ ตั้งค่าการใช้งาน ] === local TOGGLE_KEY = Enum.KeyCode.G -- กดปุ่ม G เพื่อเปิด/ปิด (เปลี่ยนปุ่มได้) -- =========================
local isInvisible = false local originalTransparencies = {} local originalHealthChangedConnection = nil
-- ฟังก์ชันทำให้อวัยวะและเสื้อผ้า ล่องหน/ปรากฏตัว local function setTransparency(char, transparencyValue) for _, part in ipairs(char:GetDescendants()) do -- ล่องหนพวกชิ้นส่วนร่างกาย if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then if transparencyValue == 1 then -- บันทึกค่าความใสเดิมไว้ก่อนซ่อน originalTransparencies[part] = part.Transparency part.Transparency = 1 else -- คืนค่าความใสเดิม part.Transparency = originalTransparencies[part] or 0 end -- ซ่อนพวกใบหน้า (Decal) elseif part:IsA("Decal") then if transparencyValue == 1 then originalTransparencies[part] = part.Transparency part.Transparency = 1 else part.Transparency = originalTransparencies[part] or 0 end end end end
-- ฟังก์ชันเปิด/ปิดโหมด ล่องหน + ยิงไม่เข้า local function toggleInvisibility() character = localPlayer.Character if not character or not character:FindFirstChild("Humanoid") then return end
end
-- ตรวจสอบการกดปุ่ม G UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == TOGGLE_KEY then toggleInvisibility() end end)
-- รีเซ็ตค่าหากตัวละครตายแล้วเกิดใหม่ localPlayer.CharacterAdded:Connect(function(newChar) character = newChar isInvisible = false if originalHealthChangedConnection then originalHealthChangedConnection:Disconnect() end end)
-- ใส่สคริปต์นี้ไว้ใน Part ที่ต้องการให้หมุน local TweenService = game:GetService("TweenService") local part = script.Parent
-- ตั้งค่าความเร็ว (วินาทีต่อการหมุน 1 รอบ) ยิ่งเลขน้อยยิ่งหมุนเร็ว local SPIN_SPEED = 4
-- ตั้งค่าคุณสมบัติการหมุน (หมุน 360 องศาแกน Y) local tweenInfo = TweenInfo.new( SPIN_SPEED, Enum.EasingStyle.Linear, -- หมุนด้วยความเร็วคงที่ Enum.EasingDirection.InOut, -1, -- -1 คือให้หมุนซ้ำไปเรื่อยๆ ไม่มีวันจบ false -- ไม่ต้องหมุนย้อนกลับ )
local targetProperties = { CFrame = part.CFrame * CFrame.Angles(0, math.rad(360), 0) }
-- สร้างและเริ่มใช้งาน Tween local spinTween = TweenService:Create(part, tweenInfo, targetProperties) spinTween:Play()
LocalScript ภายใน StarterPlayerScripts local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local Workspace = game:GetService("Workspace")
local localPlayer = Players.LocalPlayer local camera = Workspace.CurrentCamera
-- === [ ตั้งค่าการใช้งาน ] === local LOCK_KEY = Enum.KeyCode.E -- ปุ่มที่ใช้เปิด/ปิดระบบล็อคหัว (เปลี่ยนเป็นปุ่มอื่นได้) local MAX_DISTANCE = 100 -- ระยะทางสูงสุดที่จะล็อคเป้าหมายได้ (หน่วยเป็น Studs) -- =========================
local isTargeting = false local targetCharacter = nil local runConnection = nil
-- ฟังก์ชันค้นหาผู้เล่นที่ใกล้ที่สุด local function getClosestPlayer() local closestPlayer = nil local shortestDistance = MAX_DISTANCE
end
-- ฟังก์ชันอัปเดตมุมกล้องให้หันไปที่หัวเป้าหมาย local function updateCamera() if not isTargeting or not targetCharacter or not targetCharacter:FindFirstChild("Head") or (targetCharacter:FindFirstChild("Humanoid") and targetCharacter.Humanoid.Health <= 0) then -- ถ้าเป้าหมายตาย หรือหายไป ให้ยกเลิกการล็อค isTargeting = false targetCharacter = nil if runConnection then runConnection:Disconnect() end return end
end
-- ตรวจสอบการกดปุ่ม UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end -- ป้องกันการทำงานตอนพิมพ์แชท
end)