I have a script in server script service that’s supposed to add a folder to someone’s character whenever they join, but whenever the player dies the script stops adding the folders to the character. How do I fix this?
The script is in ServerScriptService
local BodyVariables = script.BodyVariables
local CharacterVariables = script.CharacterVariables
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
local Character = plr.Character or plr.CharacterAdded:Wait()
local VariableFolder1 = BodyVariables:Clone()
VariableFolder1.Parent = Character
local VariableFolder2 = CharacterVariables:Clone()
VariableFolder2.Parent = Character
end)
players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(Character)
--this triggers everytime a character is added to the player.
end)
end)
With this you’ll clone your folder into the character every time a Character gets added.
local BodyVariables = script.BodyVariables
local CharacterVariables = script.CharacterVariables
local players = game:GetService("Players")
local function FolderReplace()
local Character = plr.Character or plr.CharacterAdded:Wait()
local VariableFolder1 = BodyVariables:Clone()
VariableFolder1.Parent = Character
local VariableFolder2 = CharacterVariables:Clone()
VariableFolder2.Parent = Character
end
players.PlayerAdded:Connect(function(plr)
FolderReplace()
end)
for a, b in ipairs(players:GetPlayers()) do
b.CharacterAdded.Connect(function()
--players character got added or respawned
FolderReplace()
end)
end