this is a script to add sound, particles and damage to the player when the part is clicked. they all work FINE so no need to change those scripts, only to be added is transparency to the player, when you click the button you slowly become more and more transparent untill you are finally invisible.
local deb = false
local rate = 7 -- measured in health / s; player loses 7 health per second
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if not deb then
deb = true
script.Parent.woosh.SoundId = "rbxassetid://1839756886"
script.Parent.woosh:Play()
for i, v in pairs(plr.Character:GetDescendants()) do
if v:IsA("BasePart") then
local particle = script.Parent.ParticleEmitter:Clone()
particle.Enabled = true
particle.Parent = v
end
end
spawn(function()
while (plr.Character.Humanoid.Health > 0) do
local wt = wait()
plr.Character.Humanoid.Health = plr.Character.Humanoid.Health - (wt * rate)
end
end)
end
wait(100 / rate) -- if you ever decide to change the rate
deb = false
end)
I donât think you have to make separate topics. Replace the while loop in the code with this:
while (plr.Character.Humanoid.Health > 0) do
local wt = wait()
for _,v in pairs(plr.Character:GetDescendants()) do
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
v.Transparency = 1 - (plr.Character.Humanoid.Health / plr.Character.Humanoid.MaxHealth)
end
end
plr.Character.Humanoid.Health = plr.Character.Humanoid.Health - (wt * rate)
end
for _,v in pairs(plr.Character:GetDescendants()) do
if v:IsA("BasePart") then
v.Transparency = 1
end
end
Also, change this wait(100 / rate) to wait(plr.Character.Humanoid.MaxHealth / rate), if the playersâ MaxHealth is not 100
local deb = false
local rate = 7 -- measured in health / s; player loses 7 health per second
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if not deb then
deb = true
script.Parent.woosh.SoundId = "rbxassetid://1839756886"
script.Parent.woosh:Play()
for i, v in pairs(plr.Character:GetDescendants()) do
if v:IsA("BasePart") then
local particle = script.Parent.ParticleEmitter:Clone()
particle.Enabled = true
particle.Parent = v
end
end
local tran = 0 --Transparency
spawn(function()
while (plr.Character.Humanoid.Health > 0) do
local wt = wait()
plr.Character.Humanoid.Health = plr.Character.Humanoid.Health - (wt * rate)
tran = tran + (wt * rate * 0.01)
for _, part in pairs(plr.Character:GetDescendants()) do
if part:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then --Added check for humanoid root part
part.Transparency = tran
end
end
end
end)
end
wait(100 / rate) -- if you ever decide to change the rate
deb = false
end)
This method makes the transparency change at the same relative rate as the health, (0 -> 1).
I assume you mean the HumanoidRootPart; change this portion of his script:
for _, part in pairs(plr.Character:GetDescendants()) do
if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then
part.Transparency = tran
end
end
You can but itâs up to you, as long the code works as you intended it to be with no faults and errors, since everything is kind of âall over the placeâ. This may help others with similar problems
alright, if someone in the future needs it heres the full script:
ââ
local deb = false
local rate = 7 â measured in health / s; player loses 7 health per second
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if not deb then
deb = true
script.Parent.woosh.SoundId = ârbxassetid://1839756886â
script.Parent.woosh:Play()
for i, v in pairs(plr.Character:GetDescendants()) do
if v:IsA(âBasePartâ) then
local particle = script.Parent.ParticleEmitter:Clone()
particle.Enabled = true
particle.Parent = v
end
end
local tran = 0 --Transparency
spawn(function()
while (plr.Character.Humanoid.Health > 0) do
local wt = wait()
plr.Character.Humanoid.Health = plr.Character.Humanoid.Health - (wt * rate)
tran = tran + (wt * rate * 0.01)
for _, part in pairs(plr.Character:GetDescendants()) do
if part:IsA(âBasePartâ) and part.Name ~= âHumanoidRootPartâ then
part.Transparency = tran
end
end
end
end)
end
wait(100 / rate) â if you ever decide to change the rate
deb = false
end)
ââ