Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this Custom Character script work for like 5 seconds?

so basically im making a custom character script, that replaces the player's character with my own model. The problem im having is my script only works for like 5 second before turning the character back to normal. How would i keep this permanent? This is located inside of player starter scripts. Its also a module script inside this script

wait(1)
local player
while not player do
	wait()
	player = game:GetService('Players').LocalPlayer
end
	--local face = player.Character.Head.face:Clone()
function onSpawn()
	local char = game.ReplicatedStorage.CustomCharacter:Clone()
	--local SpawnLocation = game.Workspace.SpawnLocation
	--face.Parent = char.Head
	char.Parent = workspace
	char.Name = player.Name
	--char:MoveTo(SpawnLocation.Position)
	
	--[[for _,v in pairs(char:GetChildren()) do
 		v.BrickColor = BrickColor.new("Deep blue")
	end]]--skin color
	local prevChar = player.Character
	wait()
	player.Character = char
	prevChar:Destroy()
	
	if char:FindFirstChild("Humanoid") then
	char.Humanoid:Destroy()
	end
	local human = Instance.new("Humanoid", char)
	char.Archivable = false

	human.Died:connect(function()
	wait(1)
	onSpawn()
	wait(.1)
	player.Character.Humanoid.Running:connect(whenRunning)
	player.Character.Humanoid.Jumping:connect(whenJumping)
	player.Character.Humanoid.FallingDown:connect(whenFalling)
	player.Character.Humanoid.FreeFalling:connect(whenFalling)
	end)

local character = char
local animTbl = require(script.Animations)(character, character.Humanoid)
--Remove prints if they lag
local onGround = true
local prevAirType = 'grounded'
local inAirType = 'grounded'
local canPlayIdle = true
local canPlayWalk = false
local canPlayJump = false
local canPlayFall = false
function whenRunning(speed)
  	prevAirType = inAirType
    inAirType = 'grounded'
    onGround = true	
	if speed > 1 then
		canPlayIdle = true
		if canPlayWalk == true then
			canPlayWalk = false
			print("walk")
			animTbl:stop('idle', character.Humanoid)
			animTbl:play('walk', character.Humanoid)		
		end
	else
		canPlayWalk = true
		if canPlayIdle == true then
			canPlayIdle = false
			print("idle")
			animTbl:stop('walk', character.Humanoid)						
			animTbl:play('idle', character.Humanoid)
		end
	end
end
function whenFalling()
    prevAirType = inAirType
    inAirType = 'fall'
    onGround = false
end
function whenJumping()
    prevAirType = inAirType
    inAirType = 'jump'
    onGround = false
end

character.Humanoid.Running:connect(whenRunning)
character.Humanoid.FreeFalling:connect(whenFalling)
character.Humanoid.Jumping:connect(whenJumping)
end
	
onSpawn()

player.Character.Humanoid.Running:connect(whenRunning)
player.Character.Humanoid.Jumping:connect(whenJumping)
player.Character.Humanoid.FallingDown:connect(whenFalling)
player.Character.Humanoid.FreeFalling:connect(whenFalling)

1 answer

what i would do is just create the parts and then weld it to the player :\

2 comments

0

yea but the animations wouldnt load into the character >.>

0

what do you mean

This discussion is preserved as it was. New answers, comments, and votes are closed.