Untitled
unknown
plain_text
10 months ago
1.4 kB
18
Indexable
local TweenService = game:GetService("TweenService")
local spikesFolder = workspace:WaitForChild("Spikes") -- your folder
local distance = 10 -- how far spikes move
local speed = 2 -- movement speed
local damage = 20 -- damage given to player
-- Function to set up each spike
local function setupSpike(spike)
-- Save starting position
local startPos = spike.Position
-- Damage players on touch
spike.Touched:Connect(function(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(damage)
end
end)
-- Run the movement in a new thread
task.spawn(function()
while true do
-- Move right
local rightGoal = { Position = startPos + Vector3.new(distance, 0, 0) }
local tweenRight = TweenService:Create(spike, TweenInfo.new(speed, Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut), rightGoal)
tweenRight:Play()
tweenRight.Completed:Wait()
-- Move left
local leftGoal = { Position = startPos }
local tweenLeft = TweenService:Create(spike, TweenInfo.new(speed, Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut), leftGoal)
tweenLeft:Play()
tweenLeft.Completed:Wait()
end
end)
end
-- Loop through all spikes in the folder
for _, spike in ipairs(spikesFolder:GetChildren()) do
if spike:IsA("BasePart") then
setupSpike(spike)
end
end
Editor is loading...
Leave a Comment