Plr:loadcharacter duplicates local scripts

how to replicate: join game, wait 5 seconds, this script runs:

game.Players.CharacterAutoLoads = false
local plr = game.Players:GetChildren()[1]

local OldChar = plr.Character
local newChar = game.ReplicatedStorage.foxnoobkite:Clone()
newChar.Parent = game.Workspace
newChar.Name = plr.Name
wait()
OldChar:Destroy()
plr:LoadCharacter()
plr.Character = newChar

works fine, wait another 5 seconds for another execution
hold click, you will see local script runs once first, after the second execution, local script runs twice
Baseplate.rbxl (88.0 KB)

It’s because you placed the localscript under StarterCharacter, which means it will run every time the character resets and respawns. And the input connection inside the script keeps the thread alive and prevents the script from stopping when the player dies. So place it under StarterPlayer instead.