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

Disguise tool not changing Into a different character?

So I am making a tool so that whenever you click It, It clones a random character I made Inside of a folder called "Characters" In replicastorage, then being parented Into StarterPlayer then lastly being named as "StarterCharacter", however It appears to not change Into the NPC

(Also, I was wondering how to make the disguise tool change your name when being a spesific character, like If the disguise tool changed you Into roblox your name will be changed to "Roblox" and 2 other names)

script:

local tool = script.Parent
local Rep = game.ReplicatedStorage
local CharacterFolder = Rep.Characters

tool.Activated:Connect(function()
	local RandomCharacter = math.random(1,3)
	
	if RandomCharacter == 1 then
		local AveragePlayer = CharacterFolder["Average player"]:Clone()
		AveragePlayer.Parent = game.StarterPlayer
		AveragePlayer.Name = "StarterCharacter"
	end
	if RandomCharacter == 2 then
		local AveragePlayer = CharacterFolder.Girl:Clone()
		AveragePlayer.Parent = game.StarterPlayer
		AveragePlayer.Name = "StarterCharacter"
	end
	if RandomCharacter == 3 then
		local AveragePlayer = CharacterFolder.Troll:Clone()
		AveragePlayer.Parent = game.StarterPlayer
		AveragePlayer.Name = "StarterCharacter"
	end
	tool:Destroy()
end)

1 answer

✓ Accepted answer

Don’t put the character in the starter because the starter only works once you joined the game. Meaning you can’t change the starter player if you’re already in the game. What will you do instead is put the character in the workspace, and name it the name of the player. You can get the player by getting the character of the player using game.Players:GetPlayerFromCharacter(tool.Parent). After that make the player’s character ACTUALLY the character you’re trying to morph. After that you can put the character in the workspace and the script should look like this:


local tool = script.Parent
local Rep = game.ReplicatedStorage
local CharacterFolder = Rep.Characters

tool.Activated:Connect(function()
    local player = game.players:GetPlayerFromCharacter(tool.Parent)

    local RandomCharacter = math.random(1,3)

    if RandomCharacter == 1 then
        local AveragePlayer = CharacterFolder["Average player"]:Clone()
        AveragePlayer.Name = player.Name
        player.Character = AveragePlayer

        local rootPart = AveragePlayer:FindFirstChild("HumanoidRootPart") or AveragePlayer:FindFirstChild("Torso")
        local plrRoot = player.Character:FindFirstChild("HumanoidRootPart") or player.Character.Parent:FindFirstChild("Torso")

        if rootPart and plrRoot then
                rootPart.CFrame = plrRoot.CFrame
        end

        AveragePlayer.Parent = workspace
    end
    if RandomCharacter == 2 then
        local AveragePlayer = CharacterFolder.Girl:Clone()
        AveragePlayer.Name = player.Name
        player.Character = AveragePlayer

        local rootPart = AveragePlayer:FindFirstChild("HumanoidRootPart") or AveragePlayer:FindFirstChild("Torso")
        local plrRoot = player.Character:FindFirstChild("HumanoidRootPart") or player.Character.Parent:FindFirstChild("Torso")

        if rootPart and plrRoot then
                rootPart.CFrame = plrRoot.CFrame
        end

        AveragePlayer.Parent = workspace
    end
    if RandomCharacter == 3 then
        local AveragePlayer = CharacterFolder.Troll:Clone()
        AveragePlayer.Name = player.Name
        player.Character = AveragePlayer

        local rootPart = AveragePlayer:FindFirstChild("HumanoidRootPart") or AveragePlayer:FindFirstChild("Torso")
        local plrRoot = player.Character:FindFirstChild("HumanoidRootPart") or player.Character.Parent:FindFirstChild("Torso")

        if rootPart and plrRoot then
                rootPart.CFrame = plrRoot.CFrame
        end

        AveragePlayer.Parent = workspace
    end
    tool:Destroy()
end)

4 comments

0

Also if you want the name of the character to be not the usernane and actually in disguise, edit the Character’s Display name in the Humanoiid by adding a new line and type “AveragePlayer.Humanoid.DisplayName = “Type any name here”

0

It appears to say "Player Is not a valid member of DataModel "game"

0

Nevermind It worked! I just founded out that In line 6 you typed "game.players" you accidently made the P lowercase

0

ye lol

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