My issue with the following scripts is that the player receives the saved clothes when they die instead of when they respawned.
script: ServerScriptServices
game.Players.PlayerAdded:Connect(function(plr)
local F = Instance.new("Folder", plr)F.Name = "Stats"
local ShirtValue = Instance.new("StringValue", F)ShirtValue.Name = "ShirtID" ShirtValue.Value = "N/A"
end)
local SE = game.ReplicatedStorage.ShirtEvent
SE.OnServerEvent:Connect(function(plr)
local char = plr:WaitForChild("Character")
if plr.Stats.ShirtID.Value == "SJT" then
char:WaitForChild("Shirt").ShirtTemplate = script.Shirt1.ShirtTemplate
print("Shirt applied to "..plr.Name)
end
end)
--script: StarterCharacterScripts
local plr = game.Players.LocalPlayer
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
hum.Died:Connect(function()
print(plr.Name.. " Died!")
wait(8)
game.ReplicatedStorage.ShirtEvent:FireServer(plr)
end)
--Local script: StarterCharacterScripts
I think an easier thing to do would just be utilizing playeradded and character added in server
game.Players.PlayerAdded:Connect(function(plr)
local F = Instance.new("Folder", plr)F.Name = "Stats"
local ShirtValue = Instance.new("StringValue", F)ShirtValue.Name = "ShirtID" ShirtValue.Value = "N/A"
plr.CharacterAdded:Connect(function(char)
--its best to access either through workspace or from plr, dont use char above, may run into issues.
local Character = plr:WaitForChild("Character")
if plr.Stats.ShirtID.Value == "SJT" then
Character:WaitForChild("Shirt").ShirtTemplate = script.Shirt1.ShirtTemplate
print("Shirt applied to "..plr.Name)
end
end)
end)
I’m not sure what you mean original shirt, but I assume that the character’s shirt didn’t change? probably because the shirtid value didn’t change or not quick enough.
you can also test making the value “SJT” upon player added and not just “N/A”
no you should not use waits in this it is bad practice when you can have a listening function waiting for change to the value
game.Players.PlayerAdded:Connect(function(plr)
local F = Instance.new("Folder", plr)F.Name = "Stats"
local ShirtValue = Instance.new("StringValue", F)ShirtValue.Name = "ShirtID" ShirtValue.Value = "N/A"
local Connection
plr.CharacterAdded:Connect(function(char)
if Connection then Connection:Disconnect() end
--its best to access either through workspace or from plr, dont use char above, may run into issues.
local Character = plr:WaitForChild("Character")
--if value changed and we can detect here
if plr.Stats.ShirtID.Value == "SJT" then
Character:WaitForChild("Shirt").ShirtTemplate = script.Shirt1.ShirtTemplate
print("Shirt applied to "..plr.Name)
end
Connection = plr.Stats.ShirtID:GetPropertyChangedSignal("Value"):Connect(function()
--if value changes later on
if plr.Stats.ShirtID.Value == "SJT" then
Character:WaitForChild("Shirt").ShirtTemplate = script.Shirt1.ShirtTemplate
print("Shirt applied to "..plr.Name)
end
end)
end)
end)
although admittedly you would want to manually change the shirt in the exact code block where you intend to change the shirtvalue. I’m not sure why you are aiming for a more convoluted option here