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

A Char changer script?

I want to make a script that will help me change people into a char when they join the game. This one is not working. Put this as a script.

function Intialize(character)
	for i, child in pairs(script:GetChildren()) do
		if child.className == "Script" or child.className == "LocalScript" then
			local c = child:Clone()
			c.Parent = character
			c.Disabled = false
		end
	end
end

function Apply(obj)
	if obj.className == "Humanoid" and obj.Health > 0 and obj.MaxHealth > 0 then
		Intialize(obj.Parent)
	end
	for i, child in pairs(obj:GetChildren()) do
		Apply(child)
	end
end

Apply(game.Workspace)
game.Workspace.ChildAdded:connect(Apply)

Put this inside that script as a regular script.

wait()

ch = script.Parent
set = game.Workspace --This MUST be the original area.
id = "Alar Knight of Splintered Skies" --Do NOT Mess with it!!! Leave the next 14 lines alone.
parts = {"Right Arm", "Left Arm", "Right Leg","Left Leg","Torso","hats"}
names = {"ra","la","rl","ll","ts","ht"}

wait()

function CloneMesh(name)
	local child = set:FindFirstChild(id .. " " .. name)
	local result = nil
	if child ~= nil and child.className == "CharacterMesh" then --Leave alone. Must be "CharacterMesh"
		result = child:Clone()
		result.Parent = ch
		result = {target = result, clone = result:Clone()}
	end
	return result
end

for i=1, 5, 1 do
	if parts[i] ~= nil and names[i] ~= nil then
		do
			local name1 = parts[i]
			local name2 = names[i]
			local mesh = CloneMesh(name1)
			local part = ch:FindFirstChild(name1)
			if mesh ~= nil and part == nil then
				mesh.target:Remove()
				mesh = nil
			end
		end
	end
end

function CharacterRefresh()
	local names = {""}
	for id, name in pairs(names) do
		for index, child in pairs(ch:GetChildren()) do
			if child.className == name then
				child.Parent = nil
			end
		end
	end
end

1 answer

Any output? Also I'm not sure but when a Player respawns in a game, their character model never disappears so. If I were you I would try something like.


function Respawn(prop,player)
	if prop == "Character" then
		initialize(player)
	end
end

game.Players.PlayerAdded:(function(player)
	initialize(player)
	player.Changed:connect(function(prop) Respawn(prop,player))
end)

It's always easier working from the player than the character because the character is removed and beaten up all the time. The player is a constant object.

2 comments

0

But what's wrong with mines? I want to be able to change the package.

0

I can't tell just looking at it but here is what I do to find an error. Start using pring("something") happened. Then look in the output to see what went wrong "Where it didn't print". Tell me where and I'll look at what part of your script didn't function.

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