In my script I am attempting to make a model with a humanoid in it. The script works, but when I make the player's character the model I made, the character resets soon after the line of code runs.
The script:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
repeat wait() until player.Character
local char = player.Character
mouse.KeyDown:connect(function(key)
key = key:lower()
if key == "v" then
char.Archivable = true
local clone = char:Clone()
local model = Instance.new("Model",game.Workspace)
local ball = Instance.new("Part",model)
ball.Name = "Head"
ball.Size = Vector3.new(5,5,5)
ball.BrickColor = BrickColor.new("Really blue")
ball.FormFactor = "Custom"
ball.Shape = "Ball"
ball.CanCollide = false
ball.TopSurface = "Smooth"
ball.BottomSurface = "Smooth"
local ball2 = ball:Clone()
ball2.Name = "Torso"
ball2.Parent = model
ball2.Size = Vector3.new(6,6,6)
ball2.Transparency = 0.3
ball.Position = char.Torso.Position
ball2.Position = ball.Position
ball.Anchored = true
ball2.Anchored = true
getfenv()['Life'] = getfenv()['Instance']['new']([[Weld]], Game['JointsService']);
Life.C1 = ball2.CFrame:toObjectSpace(ball.CFrame);
Life.Part0 = ball
Life.Part1 = ball2
local humanoid = Instance.new("Humanoid")
humanoid.MaxHealth = 100
humanoid.Health = 100
humanoid.Parent = model
model.Name = player.Name
player.Character = model
end
end)
My question: Is there any way to keep the player resetting other than turning off the 'AutoCharacterLoads' property?

1 comment
Why are you using getfenv on line 30? Just define it globally if that's what you're trying to do.