Greetings all! I am currently working on a script that causes the player (or more specifically, the player’s character) to temporarily fade to translucent and back when they take damage. Although the script itself produces no errors, I have been unfortunate in getting it to work after having attempted to test it out with the Humanoid:TakeDamage
function in Play mode in Studio. As of right now I have not found any solutions to this after having searched for some time on and off the DevForum and I could do with some assistance in searching for the issue. Any and all suggestions and advice would be greatly appreciated!
The above image is the current location in the Explorer in which the script is located. (highlighted in yellow for emphasis)
--// Variables
local Players = game:GetService("Players") -- Get Player service
local TweenService = game:GetService("TweenService") -- Get Tween service
debounce = false
--// Function
Players.PlayerAdded:Connect(function(player) -- Calls function when a player joins
player.CharacterAdded:Connect(function(character) -- Calls nested function when player character spawns
local humanoid = character:WaitForChild("Humanoid")
local humanoidHealth = humanoid.Health
humanoid.HealthChanged:Connect(function(Health) -- Calls nested function when the player's health changes
if debounce then return end
if humanoidHealth < Health then -- Fires function if player's current health is lower than the stored value
debounce = true
for i, v in pairs(player.Character:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("MeshPart") then
--// Tween Info & Goal
local tweenInfo = TweenInfo.new(
0.35, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.InOut, -- EasingDirection
0, -- RepeatCount
true, -- Reverses
0 -- DelayTime
)
local tweenGoals = {Transparency = 0.6}
local tween = TweenService:Create(v, tweenInfo, tweenGoals)
tween:Play()
end
end
debounce = false -- Resets debounce
humanoidHealth = Health -- Updates variable for the next function call
end
end)
end)
end)