Need Help with Changing Character

Im trying to make it so after Larvae is done evolving, You change into a worker ant
But it’s not working tho.
Code:
game.Players.PlayerAdded:Connect(function(plr)
if plr.Character == “Larvae” then
if plr.Character.GrowScript.Growth.Value < 3 then
local clone = game.ReplicatedStorage.Ants[“Carpenter Ants”].Worker:Clone()
plr.Character = clone
clone.Parent = workspace
end
end
end)

2 Likes

here is the formatted code for anyone:

game.Players.PlayerAdded:Connect(function(plr)
if plr.Character == “Larvae” then
if plr.Character.GrowScript.Growth.Value < 3 then
local clone = game.ReplicatedStorage.Ants[“Carpenter Ants”].Worker:Clone()
plr.Character = clone
clone.Parent = workspace
        end
    end
end)

how would the character = “Larvae” do you mean the characters name?

Larvae is the name of the custom character that they morphed into.

well is there any errors? and is this in a server script?

It is in a server script but there is no errors when I test.

what if you cloned it to workspace first then change the character

Well Cloning it into workspace then changing the character would break the camera and kill the player.

try printing if the character = larvae or the carpenter ant

Hey, this doesn’t help with the post but I would recommend doing:

if plr.Character == "Larvae" and plr.Character.GrowScript.Growth.Value < 3 then

instead of using another if statement after you use the first one, this will help reduce “ends” in your script.

Would it not be

game.Players.PlayerAdded:Connect(function(plr)
    if plr.Character.Name == “Larvae” then
        if plr.Character.GrowScript.Growth.Value < 3 then
            local clone = game.ReplicatedStorage.Ants[“Carpenter Ants”].Worker:Clone()
            plr.Character = clone
            clone.Parent = workspace
        end
    end
end)

with emphasis, on the Character.Name, that way, you’d actually be able to compare the name value rather than object values.

Also, just a comment on the logic of the code snippet, this would only check if the player is a larvae when they enter the game.