What do you want to achieve? Keep it simple and clear!
I want the player to become transparent when they die for a disappearing effect. (R6)
What is the issue? Include screenshots / videos if possible!
My code wont work. I am very new to scripting on Roblox and cannot find anything.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking for help using both the assistant and looking at forums, none worked.
Here is a script I tried that wont work.
local Players = game:GetService("Players")
local function onCharacterAdded(character, player)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
local character = player.Character
if character then
character.Transparency = 1
end
end)
end
Players.PlayerAdded:Connect(onCharacterAdded)
--Generated
By the way, this is my first forum post so if I did anything wrong please let me know. And I am very new to scripting as well.
Oh- and also, I don’t want the player to destroy or delete itself, I just want it transparent.
The character of the player is a model and models do not have a transparency property. Instead you can loop through the player’s character and change the transparency of each part directly
replace this:
character.Transparency = 1
with this:
for _, part in character:GetDescendants() do
if part:IsA("BasePart") then
part.Transparency = 1
end
end
For some reason, the player still doesn’t disappear or turn transparent on death. The script is a LocalScript located in StarterCharacterScripts.
Here is the script so far:
local Players = game:GetService("Players")
local function onCharacterAdded(character, player)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
local character = player.Character
if character then
for _, part in character:GetDescendants() do
if part:IsA("BasePart") then
part.Transparency = 1
end
end
end
end)
end
Players.PlayerAdded:Connect(onCharacterAdded)
--Generated
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
-- Iterate through all parts in the character
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") then
part.Transparency = 1 -- Set the transparency to 1 to make the part invisible
end
end
end)
end
local function onPlayerAdded(player)
-- Connect the function for the player's character when it's added
player.CharacterAdded:Connect(function(character)
onCharacterAdded(character)
end)
-- If the character already exists, connect the function immediately
if player.Character then
onCharacterAdded(player.Character)
end
end
-- Connect the function for all existing players
for _, player in ipairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
-- Connect the function for players joining the game
Players.PlayerAdded:Connect(onPlayerAdded)
The script is run after the character is added(since its parented to startercharacterscripts), therefore the playeradded signal never fires
try replacing everything with this
local humanoid = script.Parent:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
local character = script.Parent
if character then
for _, part in character:GetDescendants() do
if part:IsA("BasePart") then
part.Transparency = 1
end
end
end
end)