I am making checkpoint systems and when a player touches a checkpoint it will do little tweens downward and rotate. It works, however, when there are two players that touch the same checkpoint before the animation of the one who first touched it finished it breaks.
This is the entirety of the checkpoint script (Scroll down to comment "Checkpoint animation for the tween part)
–Made by Its4Realzies
for i, child in ipairs (script.Parent:GetChildren())do
if child.ClassName == ‘Part’ then
child.Touched:connect(function(hit)
–Check for Player
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
–Check for Player’s humanoid and that its alive
local humanoid = hit.Parent:FindFirstChild(“Humanoid”)
if not humanoid or humanoid.Health <= 0 then return end
--Difines leaderstats
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then return end
local checkpointStat = leaderstats:FindFirstChild("Stage")
local deathStat = leaderstats:FindFirstChild("Deaths")
if child.Name ~= "Reset" then
--Checks if its the next checkpoint thats been touched
local checkpointNumber = string.gsub(child.Name, 'Checkpoint', '')
if tonumber(checkpointNumber) == checkpointStat.Value + 1 then
print("Stage update called")
checkpointStat.Value = tonumber(checkpointNumber)
--Checkpoint sound
local ding = script.Ding:Clone()
ding.Parent = child
ding:Play()
game.Debris:AddItem(ding, ding.TimeLength)
--Checkpoint particle
local newAttachment = Instance.new("Attachment")
newAttachment.Name = "ParticleAttachment"
newAttachment.Parent = child
local newParticle = script.Particle:Clone()
newParticle.Parent = newAttachment
newParticle.Changed:connect(function()
wait(0.15)
newParticle.Enabled = false
game.Debris:AddItem(newParticle, 0.75)
end)
newParticle.Enabled = true
--Checkpoint animation
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true, 0)
local Goals = {
Color = Color3.fromRGB(248, 248, 248);
Reflectance = -2;
Orientation = Vector3.new(child.Orientation.X, child.Orientation.Y + 360, child.Orientation.Z);
Position = Vector3.new(child.Position.X, child.Position.Y-0.95, child.Position.Z)
}
local tween = TweenService:Create(child, Info, Goals)
tween:Play()
end
elseif humanoid.Health > 99 then
checkpointStat.Value = 1
deathStat.Value = -1
humanoid.Health = 0
--Reset sound
local fart = script.Reset:Clone()
fart.Parent = hit.Parent:FindFirstChild("Torso")
fart:Play()
game.Debris:AddItem(fart, fart.TimeLength)
--Reset animation
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out, 0, true, 0)
local Goals = {
Reflectance = -2;
Size = Vector3.new(child.Size.X + 10, child.Size.Y, child.Size.Z + 10);
}
local tween = TweenService:Create(child, Info, Goals)
tween:Play()
wait(1)
end
end)
end
end