I am trying to make it so players have unique starter characters based on what the value of a certain stat attached to them is.
The issue with this is that the newest player to join/change their value will override the starter character for ALL players instead of just that specific player.
I have tried fixes such as not running the code in functions, having the change detector in the player-added function, and moving the script to workspace but neither of those seemed to work.
The code I made is below.
local function change_character(plr)
local sp = game.StarterPlayer
if plr:WaitForChild("EquippedCostume").Value ~= "None" then
if sp:FindFirstChild("StarterCharacter") ~= nil then sp:FindFirstChild("StarterCharacter"):Destroy() else end
newcostume = game.ServerStorage.Costumes:FindFirstChild(plr:WaitForChild("EquippedCostume").Value):Clone()
newcostume.Name = "StarterCharacter"
newcostume.Parent = sp
plr:LoadCharacter()
else
sp:FindFirstChild("StarterCharacter"):Destroy()
plr:LoadCharacter()
end
end
local function change_characterNoLoad(plr)
local sp = game.StarterPlayer
task.wait()
if plr:WaitForChild("EquippedCostume").Value ~= "None" then
if sp:FindFirstChild("StarterCharacter") ~= nil then sp:FindFirstChild("StarterCharacter"):Destroy() else end
repeat
task.wait()
newcostume = game.ServerStorage.Costumes:FindFirstChild(plr.EquippedCostume.Value):Clone()
newcostume.Name = "StarterCharacter"
newcostume.Parent = sp
until sp:FindFirstChild("StarterCharacter") ~= nil
else
sp:FindFirstChild("StarterCharacter"):Destroy()
end
end
game.Players.PlayerAdded:Connect(function(plr)
task.wait(3)
change_character(plr)
plr:WaitForChild("EquippedCostume"):GetPropertyChangedSignal("Value"):Connect(function()
task.wait(0.25)
change_characterNoLoad(plr)
end)
end)
How would I go about fixing this code so a player changing their starter character only applies to them and not the entire server, as well as that starter character still showing for everyone including the player?