เตรียม Humanoid, Animator และ AnimationTrack ใหม่ทุกครั้งที่ Character ถูกสร้าง
LocalScript — StarterPlayerScripts
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local RUN_ANIMATION_ID = 0 -- ใส่ Animation ID ของคุณ
local NORMAL_SPEED = 16
local runTrack
local function setupCharacter(character)
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")
or Instance.new("Animator", humanoid)
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://" .. RUN_ANIMATION_ID
runTrack = animator:LoadAnimation(animation)
humanoid.WalkSpeed = NORMAL_SPEED
end
player.CharacterAdded:Connect(setupCharacter)
if player.Character then
setupCharacter(player.Character)
end
เชื่อม Touched ให้ Part ทุกก้อนในโฟลเดอร์ Lava Bricks
Script — ServerScriptService
local lavaBricks = workspace
:WaitForChild("Lava Bricks")
:GetChildren()
for _, lavaBrick in ipairs(lavaBricks) do
lavaBrick.Touched:Connect(function(hit)
local character = hit:FindFirstAncestorOfClass("Model")
local humanoid = character
and character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = 0
end
end)
end
!สร้าง Folder ใน Workspace ชื่อ Lava Bricks แล้ววาง Part ลาวาทุกก้อนไว้ภายใน
04.3 · DAMAGE LAVAEVENT
ลาวาลดพลังชีวิต
สร้างลาวาที่ลด Health ครั้งละ 10 และมีคูลดาวน์แยกตามตัวละคร
Script — Lava Part
local lava = script.Parent
local DAMAGE = 10
local COOLDOWN = 1
local coolingDown = {}
lava.Touched:Connect(function(hit)
local character = hit:FindFirstAncestorOfClass("Model")
local humanoid = character
and character:FindFirstChildOfClass("Humanoid")
if not humanoid or coolingDown[humanoid] then
return
end
coolingDown[humanoid] = true
humanoid:TakeDamage(DAMAGE)
task.delay(COOLDOWN, function()
coolingDown[humanoid] = nil
end)
end)
!วาง Script ไว้ใน Part ลาวา ปรับ DAMAGE และ COOLDOWN เพื่อเปลี่ยนความยาก
04.4 · CHECKPOINT COLORSYSTEM
จับคู่ Checkpoint กับ Team
ตั้ง TeamColor ของ Checkpoint ตาม Team ที่มีชื่อเดียวกัน
Script — ServerScriptService
local Teams = game:GetService("Teams")
local checkpoints = workspace
:WaitForChild("Checkpoints")
:GetChildren()
for _, checkpoint in ipairs(checkpoints) do
local team = Teams:FindFirstChild(checkpoint.Name)
if team and checkpoint:IsA("SpawnLocation") then
checkpoint.TeamColor = team.TeamColor
end
end
!ชื่อ SpawnLocation ในโฟลเดอร์ Checkpoints ต้องตรงกับชื่อ Team ทุกตัวอักษร
local Players = game:GetService("Players")
local MIN_HEIGHT = 5
local MAX_HEIGHT = 25
local function calculateFallDamage(fallHeight, maxHealth)
if fallHeight <= MIN_HEIGHT then
return 0
elseif fallHeight >= MAX_HEIGHT then
return maxHealth
end
local ratio = (fallHeight - MIN_HEIGHT)
/ (MAX_HEIGHT - MIN_HEIGHT)
return ratio * maxHealth
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local initialHeight
humanoid.FreeFalling:Connect(function(isFalling)
if isFalling then
initialHeight = rootPart.Position.Y
elseif initialHeight then
local fallHeight = initialHeight - rootPart.Position.Y
local damage = calculateFallDamage(
fallHeight,
humanoid.MaxHealth
)
humanoid:TakeDamage(damage)
initialHeight = nil
end
end)
end)
end)
local trap = script.Parent
local activated = false
trap.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or activated then
return
end
activated = true
for i = 1, 3 do
trap.Transparency = 0.5
task.wait(0.4)
trap.Transparency = 0
task.wait(0.4)
end
trap.CanCollide = false
trap.Anchored = false
end)
local trap = script.Parent
local activated = false
trap.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or activated then
return
end
activated = true
for i = 1, 3 do
trap.Transparency = 0.5
task.wait(0.4)
trap.Transparency = 0
task.wait(0.4)
end
trap.Transparency = 1
trap.CanCollide = false
task.wait(3)
trap.Transparency = 0
trap.CanCollide = true
activated = false
end)
หมุน Spinner รอบแกน Y ต่อเนื่องด้วยลูปและเวลาของแต่ละเฟรม
Script — Spinner
local part = script.Parent
local rotationSpeed = 90
while true do
local dt = task.wait()
local rotationAmount = math.rad(rotationSpeed * dt)
part.CFrame = part.CFrame *
CFrame.Angles(0, rotationAmount, 0)
end
local platform = script.Parent
local pointA = platform.Position
local pointB = pointA + Vector3.new(0, 0, 30)
while true do
for i = 0, 1, 0.02 do
platform.Position = pointA:Lerp(pointB, i)
task.wait()
end
task.wait(1)
for i = 0, 1, 0.02 do
platform.Position = pointB:Lerp(pointA, i)
task.wait()
end
task.wait(1)
end
local trap = script.Parent
local activated = false
trap.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or activated then
return
end
activated = true
local sound = trap:WaitForChild("Sound")
sound:Play()
for i = 1, 3 do
trap.Transparency = 0.5
task.wait(0.4)
trap.Transparency = 0
task.wait(0.4)
end
trap.CanCollide = false
trap.Anchored = false
end)