I have a custom character system that changes a players character into a custom one.
local respawnDelay = 3
game.Players.CharacterAutoLoads = false
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Died:Connect(function()
wait(respawnDelay)
player:LoadCharacter()
repeat wait() until
player.PlayerGui.ChosenCreature.Value ~= nil
local newmodel = player.PlayerGui.ChosenCreature.Value:Clone()
wait()
newmodel.Parent = game.Workspace
wait()
newmodel.Name = player.Name
repeat wait() until
newmodel.Parent == game.Workspace
player.Character = newmodel
wait()
player.PlayerGui.ChooseCreature.Enabled = false
end)
end
end)
player:LoadCharacter()
repeat wait() until
player.PlayerGui.ChosenCreature.Value ~= nil
local newmodel = player.PlayerGui.ChosenCreature.Value:Clone()
wait()
newmodel.Parent = game.Workspace
wait()
newmodel.Name = player.Name
repeat wait() until
newmodel.Parent == game.Workspace
player.Character = newmodel
wait()
player.PlayerGui.ChooseCreature.Enabled = false
end)
a gui opens and the player must select a model to become before the character is changed.
during this time the character remains the same as when the player joined.
my problem is when I use a tool with .Equipped or .Activated, etc, the tool will only work before changing characters, after which the tool will completely ignore the script.
the script is enabled and does exist in the tool, and the tool is also in the backpack were it should be, but despite that changing characters will break it.
is there something Im missing when changing characters that allows tools to be used?
By changing characters, you are removing any previously connected functions to that previous character. You have to reconnect the functions to the new character. Also remember that any tool a player has equipped is stored inside the character, so by replacing the character you are also removing any tool the player has equipped.
I checked if the tool is in the new characters inventory, and it is. but how should I “reconnect” the tool? I tried disabling then re-enabling the script but to no avail.
I called clearallchildren() on the player’s backpack and put in the new tools right after player.character was set, but the tool still wont work. were on my script should I do this at?
local debounce = false
local cooldownnum = 5
function use()
if not debounce then
debounce = true
print("fired")
local mover = Instance.new("BodyVelocity")
mover.Parent = script.Parent.Parent.HumanoidRootPart
mover.MaxForce = Vector3.new(100000,0,100000)
mover.Velocity = script.Parent.Parent.HumanoidRootPart.CFrame.LookVector * 90
wait(1)
mover:Destroy()
cooldown()
end
end
function cooldown()
local previousname = script.Parent.Name
local currentnum = cooldownnum
script.Parent.Name = currentnum
for i = 1, cooldownnum do
wait(1)
currentnum = currentnum - 1
script.Parent.Name = currentnum
end
script.Parent.Name = previousname
debounce = false
end
script.Parent.Equipped:Connect(use)
the script inserts and removes a bodymover into the character which causes the character to “charge” forward. it works before changing into the new custom character but stops working afterward.
im not quite sure that this script is a problem though as I made a simple .Equipped function that prints something when equipped, and even that failed to work. I even switched it to a localscript instead of a normal script. no matter what I cant get it to work after changing my character it will only work before changing.
I moved the tool to replicatedstorage, and had the tool cloned to the player’s backpack while changing, but the .Equipped function still wont run, I can still print stuff, its just I cant use any functions
I asked another post about custom characters and they found the solution to my problem, my custom characters were missing a few things such as a left arm and a shoulder joint. adding these fixes the problem.