local Players = game:GetService("Players")
local player = owner
local character = player.Character or player.CharacterAdded:Wait()
-- Clone script to StarterCharacterScripts
local function cloneToStarterCharacterScripts()
local starterCharacterScripts = game:GetService("StarterPlayer"):FindFirstChild("StarterCharacterScripts")
if not starterCharacterScripts then
starterCharacterScripts = Instance.new("Folder")
starterCharacterScripts.Name = "StarterCharacterScripts"
starterCharacterScripts.Parent = game:GetService("StarterPlayer")
end
local clone = script:Clone()
clone.Parent = starterCharacterScripts
end
-- Ensure script is cloned if not already in StarterCharacterScripts
if not script.Parent:IsDescendantOf(game:GetService("StarterPlayer")) then
cloneToStarterCharacterScripts()
end
local function createBackAttachment()
local backPart = Instance.new("Part")
backPart.Name = "BackAccessory"
backPart.Size = Vector3.new(1, 1, 1)
backPart.CanCollide = false
backPart.Massless = true
backPart.Anchored = false
backPart.Transparency = 0
backPart.Parent = character
-- Cria o Mesh
local mesh = Instance.new("SpecialMesh")
mesh.MeshType = Enum.MeshType.FileMesh
mesh.MeshId = "rbxassetid://18233636977" -- Substitua com seu MeshId válido
mesh.TextureId = "rbxassetid://2811131518" -- Substitua com seu TextureId válido
mesh.Scale = Vector3.new(0.5, 0.5, 0.5)
mesh.Parent = backPart
-- Obtém o UpperTorso ou Torso
local upperTorso = character:FindFirstChild("UpperTorso") or character:FindFirstChild("Torso")
if not upperTorso then
warn("UpperTorso ou Torso não encontrado!")
return backPart
end
-- Posiciona o Part nas costas
backPart.CFrame = upperTorso.CFrame * CFrame.new(0, 0.2, 1)
-- Cria e configura o Weld
local weld = Instance.new("Weld")
weld.Name = "BackWeld"
weld.Part0 = upperTorso
weld.Part1 = backPart
weld.C0 = CFrame.new(0, 0.2, 1) * CFrame.Angles(math.rad(38), math.rad(160), 0)
weld.Parent = backPart
return backPart
end
-- Play Sound
local function playSound(backPart)
local sound = Instance.new("Sound")
sound.Parent = backPart
sound.SoundId = "rbxassetid://705837992"
sound.Volume = 0.086
sound:Play()
wait(1)
sound:Stop()
end
-- Function to create shaking effect
local function shake(part)
local weld = part:FindFirstChild("BackWeld")
if not weld then return end
local originalC0 = weld.C0
local duration = 1
local intensity = 0.08
local frequency = 80 -- Higher frequency means faster shaking
local startTime = tick()
-- Create a separate coroutine for the shaking
task.spawn(function()
while tick() - startTime < duration do
local timeElapsed = tick() - startTime
local xOffset = math.sin(timeElapsed * frequency) * intensity
local yOffset = math.cos(timeElapsed * frequency) * intensity
weld.C0 = originalC0 * CFrame.new(xOffset, yOffset, 0)
task.wait()
end
weld.C0 = originalC0
end)
end
-- Create the back attachment when character spawns
local backPart = createBackAttachment()
-- Connect to character's health changes
local humanoid = character:WaitForChild("Humanoid")
local lastHealth = humanoid.Health
humanoid.HealthChanged:Connect(function(health)
if health < lastHealth then
-- Restore health to max
humanoid.Health = humanoid.MaxHealth
-- Trigger shaking and sound
shake(backPart)
playSound(backPart)
end
lastHealth = humanoid.Health
end)
-- Handle character respawning
player.CharacterAdded:Connect(function(newCharacter)
character = newCharacter
humanoid = character:WaitForChild("Humanoid")
lastHealth = humanoid.Health
backPart = createBackAttachment()
humanoid.HealthChanged:Connect(function(health)
if health < lastHealth then
-- Restore health to max
humanoid.Health = humanoid.MaxHealth
-- Trigger shaking and sound
shake(backPart)
playSound(backPart)
end
lastHealth = humanoid.Health
end)
end)