I am a beginner scripter, I am currently working on my first game which is a murder mystery type of game and when you load into the map when the round starts it changes your characters appearance to one of a model located in a folder in replicated storage, how do i make it so when you are in the round and type in the chat, instead of it displaying your username it displays the models name in the chat, for instance instead of Below_AverageGenius my name when i type in the chat would be Adam. And how could I make it so the script resets your name back to normal once you are back in the lobby? Any help would be appreciated, thank you
Wait, what do you mean by one of a model, like a randomly selected model in that folder?
Yes that is what I mean, When you get teleported to the map at the beginning of the round it changes your character’s appearance to be a randomly selected character model in that folder
okay, but what’s the folders name? I have the script ready but I left it blank.
the folders name is “Characters”
here,
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local characterModelsFolder = ReplicatedStorage:WaitForChild("Characters")
local function assignRoleAndChangeName(player)
local randomModel = characterModelsFolder:GetChildren()[math.random(1, #characterModelsFolder:GetChildren())]
local originalDisplayName = player.DisplayName
player:SetAttribute("OriginalDisplayName", originalDisplayName)
player.DisplayName = randomModel.Name
local character = player.Character
if character and randomModel then
for _, child in pairs(character:GetChildren()) do
if child:IsA("Accessory") or child:IsA("Clothing") or child:IsA("Shirt") or child:IsA("Pants") then
child:Destroy()
end
end
for _, part in ipairs(randomModel:GetChildren()) do
local clone = part:Clone()
clone.Parent = character
end
end
end
local function resetDisplayName(player)
local original = player:GetAttribute("OriginalDisplayName")
if original then
player.DisplayName = original
player:SetAttribute("OriginalDisplayName", nil)
end
end
-- I have no idea how your round system works, but if you can just put your starting round function or something else that starts a round, then when you do call the assignRoleAndChangeName() function to the killer or murderer.
also reply with your round handler and role handler so i can add the remaining. If it dosent work ill try my best to fix it.
Im sorry, when i say im a beginner i mean like I just started 3 days ago… If i send my round system script would that help? It uses remote events to select the players role.
It would still help, just because it uses remote events does not mean its not going to be helpful
local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local StatusValue = ReplicatedStorage:WaitForChild(“StatusValue”)
local Maps = game.ServerStorage:WaitForChild(“Maps”):GetChildren()
local inGameFolder = workspace:WaitForChild(“InGame”)
local Lobby = workspace:WaitForChild(“Lobby”)
local spawnCFrame = Lobby:WaitForChild(“SpawnLocation”).CFrame + Vector3.yAxis * 5
local roleChosenEvent = ReplicatedStorage:WaitForChild(“RoleChosen”)
local intermission = 2
local preparationTime = 5
local gameTime = 120
local minPlayers = 3
local WinningAmount = 25
local murdererPlr – Track murderer globally
local gameEnded = false – Flag for handling game termination
local function toggleSpectateGUI(plr, enabled)
local playerGui = plr:FindFirstChild(“PlayerGui”)
if playerGui then
local spectateGUI = playerGui:FindFirstChild(“SpectateGUI”)
if spectateGUI then
spectateGUI.Enabled = enabled
end
end
end
local function applyAppearance(player, characterModel)
local character = player.Character
if not character then return end
-- Ensure humanoid and root part exist
local humanoid = character:FindFirstChild("Humanoid")
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoid and humanoidRootPart then
-- Hide player name and health bar
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
-- Destroy old appearance elements
for _, obj in ipairs(character:GetChildren()) do
if obj:IsA("Accessory") or obj:IsA("Shirt") or obj:IsA("Pants")
or obj:IsA("BodyColors") or obj:IsA("CharacterMesh") then
obj:Destroy()
end
end
-- Apply all assets from the model
for _, obj in ipairs(characterModel:GetChildren()) do
if obj:IsA("Accessory") or obj:IsA("Shirt") or obj:IsA("Pants")
or obj:IsA("BodyColors") or obj:IsA("CharacterMesh") then
local clonedObj = obj:Clone()
clonedObj.Parent = character
elseif obj:IsA("HumanoidDescription") then
humanoid:ApplyDescription(obj)
end
end
-- Apply the correct face texture
local playerHead = character:FindFirstChild("Head")
local modelHead = characterModel:FindFirstChild("Head")
if playerHead and modelHead then
-- Copy Face decal
local modelFace = modelHead:FindFirstChildWhichIsA("Decal")
if modelFace then
local playerFace = playerHead:FindFirstChildWhichIsA("Decal")
if not playerFace then
playerFace = Instance.new("Decal")
playerFace.Name = "Face"
playerFace.Parent = playerHead
end
playerFace.Texture = modelFace.Texture
end
-- Copy BillboardGui
local modelBillboardGui = modelHead:FindFirstChildWhichIsA("BillboardGui")
if modelBillboardGui then
local clonedBillboardGui = modelBillboardGui:Clone()
clonedBillboardGui.Parent = playerHead
end
end
if modelRagdollScript then
local clonedRagdoll = modelRagdollScript:Clone()
clonedRagdoll.Parent = character
end
if modelDeathScript then
local clonedDeath = modelDeathScript:Clone()
clonedDeath.Parent = character
end
-- Set character position
local modelRootPart = characterModel:FindFirstChild("HumanoidRootPart")
if modelRootPart then
humanoidRootPart.CFrame = modelRootPart.CFrame
end
end
end
local function onPlayerRemoving(player)
if murdererPlr and player == murdererPlr then
gameEnded = true
StatusValue.Value = “Murderer left! Game ending…”
end
end
Players.PlayerRemoving:Connect(onPlayerRemoving)
while true do
for count = intermission, 1, -1 do
task.wait(1)
StatusValue.Value = "Intermission " … count
end
repeat
task.wait(2)
StatusValue.Value = "Minimum " .. minPlayers .. " players required"
until #Players:GetPlayers() >= minPlayers
local chosenMap = Maps[math.random(#Maps)]
StatusValue.Value = chosenMap.Name .. " has been chosen!"
task.wait(5)
local newMap = chosenMap:Clone()
newMap.Name = "Map"
newMap.Parent = workspace
repeat
task.wait(3)
until newMap and newMap:IsDescendantOf(workspace) and newMap:FindFirstChild("Spawns")
task.wait(3)
local spawns = newMap.Spawns:GetChildren()
local availableCharacters = ReplicatedStorage:WaitForChild("Characters"):GetChildren()
local inGamePlayers = {}
for _, plr in ipairs(Players:GetPlayers()) do
if not plr.Character or #availableCharacters == 0 then continue end
local chosenCharacterIndex = math.random(#availableCharacters)
local chosenCharacter = availableCharacters[chosenCharacterIndex]:Clone()
table.remove(availableCharacters, chosenCharacterIndex)
applyAppearance(plr, chosenCharacter)
local humanoidRootPart = plr.Character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local randomSpawn = spawns[math.random(#spawns)]
humanoidRootPart.CFrame = randomSpawn.CFrame + Vector3.yAxis * 5
end
toggleSpectateGUI(plr, false)
plr.Character.Parent = inGameFolder
table.insert(inGamePlayers, plr.Character)
local humanoid = plr.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Died:Connect(function()
toggleSpectateGUI(plr, true)
end)
end
end
murderer = inGamePlayers[math.random(#inGamePlayers)]
murdererPlr = Players:GetPlayerFromCharacter(murderer)
table.remove(inGamePlayers, table.find(inGamePlayers, murderer))
roleChosenEvent:FireClient(murdererPlr, "MURDERER")
local sheriff = inGamePlayers[math.random(#inGamePlayers)]
local sheriffPlr = Players:GetPlayerFromCharacter(sheriff)
table.remove(inGamePlayers, table.find(inGamePlayers, sheriff))
roleChosenEvent:FireClient(sheriffPlr, "SHERIFF")
for _, plrChar in ipairs(inGamePlayers) do
local plr = Players:GetPlayerFromCharacter(plrChar)
roleChosenEvent:FireClient(plr, "INNOCENT")
end
local weaponCache = {
murdererTool = ReplicatedStorage:FindFirstChild("Knife"),
sheriffTool = ReplicatedStorage:FindFirstChild("Revolver")
}
for count = preparationTime, 1, -1 do
StatusValue.Value = "Prepare " .. count
task.wait(1)
end
if weaponCache.murdererTool and murdererPlr then
local newKnife = weaponCache.murdererTool:Clone()
newKnife.Parent = murdererPlr.Backpack
end
if weaponCache.sheriffTool and sheriffPlr then
local newRevolver = weaponCache.sheriffTool:Clone()
newRevolver.Parent = sheriffPlr.Backpack
end
local winner = "Innocents"
while gameTime > 0 and not gameEnded do
StatusValue.Value = gameTime
task.wait(1)
gameTime -= 1
local alivePlayers = {}
for _, char in ipairs(inGameFolder:GetChildren()) do
local humanoid = char:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 then
table.insert(alivePlayers, char)
end
end
if not murderer or not murderer:FindFirstChild("Humanoid") or murderer:FindFirstChild("Humanoid").Health <= 0 then
break
elseif #alivePlayers == 1 and alivePlayers[1] == murderer then
winner = "Murderer (" .. murderer.Name .. ")"
break
end
end
StatusValue.Value = "The " .. winner .. " won the game!"
local winSounds = {
Murderer = ReplicatedStorage:FindFirstChild("MurdererWinSound"),
Innocents = ReplicatedStorage:FindFirstChild("InnocentsWinSound")
}
StatusValue.Value = "The " .. winner .. " won the game!"
-- Play the corresponding win sound
if winner:match("Murderer") and winSounds.Murderer then
winSounds.Murderer:Play()
elseif winner == "Innocents" and winSounds.Innocents then
winSounds.Innocents:Play()
end
task.wait(5)
for _, plr in ipairs(Players:GetPlayers()) do
plr:LoadCharacter()
end
newMap:Destroy()
end
Sorry, but I cant read it properly because of the cuts, for all in one just
– Add 3 backticks
Here will be the script
– Add another 3 backticks
and backticks are these `
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StatusValue = ReplicatedStorage:WaitForChild("StatusValue")
local Maps = game.ServerStorage:WaitForChild("Maps"):GetChildren()
local inGameFolder = workspace:WaitForChild("InGame")
local Lobby = workspace:WaitForChild("Lobby")
local spawnCFrame = Lobby:WaitForChild("SpawnLocation").CFrame + Vector3.yAxis * 5
local roleChosenEvent = ReplicatedStorage:WaitForChild("RoleChosen")
local intermission = 2
local preparationTime = 5
local gameTime = 120
local minPlayers = 3
local WinningAmount = 25
local murdererPlr -- Track murderer globally
local gameEnded = false -- Flag for handling game termination
local function toggleSpectateGUI(plr, enabled)
local playerGui = plr:FindFirstChild("PlayerGui")
if playerGui then
local spectateGUI = playerGui:FindFirstChild("SpectateGUI")
if spectateGUI then
spectateGUI.Enabled = enabled
end
end
end
local function applyAppearance(player, characterModel)
local character = player.Character
if not character then return end
-- Ensure humanoid and root part exist
local humanoid = character:FindFirstChild("Humanoid")
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoid and humanoidRootPart then
-- Hide player name and health bar
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
-- Destroy old appearance elements
for _, obj in ipairs(character:GetChildren()) do
if obj:IsA("Accessory") or obj:IsA("Shirt") or obj:IsA("Pants")
or obj:IsA("BodyColors") or obj:IsA("CharacterMesh") then
obj:Destroy()
end
end
-- Apply all assets from the model
for _, obj in ipairs(characterModel:GetChildren()) do
if obj:IsA("Accessory") or obj:IsA("Shirt") or obj:IsA("Pants")
or obj:IsA("BodyColors") or obj:IsA("CharacterMesh") then
local clonedObj = obj:Clone()
clonedObj.Parent = character
elseif obj:IsA("HumanoidDescription") then
humanoid:ApplyDescription(obj)
end
end
-- Apply the correct face texture
local playerHead = character:FindFirstChild("Head")
local modelHead = characterModel:FindFirstChild("Head")
if playerHead and modelHead then
-- Copy Face decal
local modelFace = modelHead:FindFirstChildWhichIsA("Decal")
if modelFace then
local playerFace = playerHead:FindFirstChildWhichIsA("Decal")
if not playerFace then
playerFace = Instance.new("Decal")
playerFace.Name = "Face"
playerFace.Parent = playerHead
end
playerFace.Texture = modelFace.Texture
end
-- Copy BillboardGui
local modelBillboardGui = modelHead:FindFirstChildWhichIsA("BillboardGui")
if modelBillboardGui then
local clonedBillboardGui = modelBillboardGui:Clone()
clonedBillboardGui.Parent = playerHead
end
end
if modelRagdollScript then
local clonedRagdoll = modelRagdollScript:Clone()
clonedRagdoll.Parent = character
end
if modelDeathScript then
local clonedDeath = modelDeathScript:Clone()
clonedDeath.Parent = character
end
-- Set character position
local modelRootPart = characterModel:FindFirstChild("HumanoidRootPart")
if modelRootPart then
humanoidRootPart.CFrame = modelRootPart.CFrame
end
end
end
local function onPlayerRemoving(player)
if murdererPlr and player == murdererPlr then
gameEnded = true
StatusValue.Value = "Murderer left! Game ending..."
end
end
Players.PlayerRemoving:Connect(onPlayerRemoving)
while true do
for count = intermission, 1, -1 do
task.wait(1)
StatusValue.Value = "Intermission " .. count
end
repeat
task.wait(2)
StatusValue.Value = "Minimum " .. minPlayers .. " players required"
until #Players:GetPlayers() >= minPlayers
local chosenMap = Maps[math.random(#Maps)]
StatusValue.Value = chosenMap.Name .. " has been chosen!"
task.wait(5)
local newMap = chosenMap:Clone()
newMap.Name = "Map"
newMap.Parent = workspace
repeat
task.wait(3)
until newMap and newMap:IsDescendantOf(workspace) and newMap:FindFirstChild("Spawns")
task.wait(3)
local spawns = newMap.Spawns:GetChildren()
local availableCharacters = ReplicatedStorage:WaitForChild("Characters"):GetChildren()
local inGamePlayers = {}
for _, plr in ipairs(Players:GetPlayers()) do
if not plr.Character or #availableCharacters == 0 then continue end
local chosenCharacterIndex = math.random(#availableCharacters)
local chosenCharacter = availableCharacters[chosenCharacterIndex]:Clone()
table.remove(availableCharacters, chosenCharacterIndex)
applyAppearance(plr, chosenCharacter)
local humanoidRootPart = plr.Character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local randomSpawn = spawns[math.random(#spawns)]
humanoidRootPart.CFrame = randomSpawn.CFrame + Vector3.yAxis * 5
end
toggleSpectateGUI(plr, false)
plr.Character.Parent = inGameFolder
table.insert(inGamePlayers, plr.Character)
local humanoid = plr.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Died:Connect(function()
toggleSpectateGUI(plr, true)
end)
end
end
murderer = inGamePlayers[math.random(#inGamePlayers)]
murdererPlr = Players:GetPlayerFromCharacter(murderer)
table.remove(inGamePlayers, table.find(inGamePlayers, murderer))
roleChosenEvent:FireClient(murdererPlr, "MURDERER")
local sheriff = inGamePlayers[math.random(#inGamePlayers)]
local sheriffPlr = Players:GetPlayerFromCharacter(sheriff)
table.remove(inGamePlayers, table.find(inGamePlayers, sheriff))
roleChosenEvent:FireClient(sheriffPlr, "SHERIFF")
for _, plrChar in ipairs(inGamePlayers) do
local plr = Players:GetPlayerFromCharacter(plrChar)
roleChosenEvent:FireClient(plr, "INNOCENT")
end
local weaponCache = {
murdererTool = ReplicatedStorage:FindFirstChild("Knife"),
sheriffTool = ReplicatedStorage:FindFirstChild("Revolver")
}
for count = preparationTime, 1, -1 do
StatusValue.Value = "Prepare " .. count
task.wait(1)
end
if weaponCache.murdererTool and murdererPlr then
local newKnife = weaponCache.murdererTool:Clone()
newKnife.Parent = murdererPlr.Backpack
end
if weaponCache.sheriffTool and sheriffPlr then
local newRevolver = weaponCache.sheriffTool:Clone()
newRevolver.Parent = sheriffPlr.Backpack
end
local winner = "Innocents"
while gameTime > 0 and not gameEnded do
StatusValue.Value = gameTime
task.wait(1)
gameTime -= 1
local alivePlayers = {}
for _, char in ipairs(inGameFolder:GetChildren()) do
local humanoid = char:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 then
table.insert(alivePlayers, char)
end
end
if not murderer or not murderer:FindFirstChild("Humanoid") or murderer:FindFirstChild("Humanoid").Health <= 0 then
break
elseif #alivePlayers == 1 and alivePlayers[1] == murderer then
winner = "Murderer (" .. murderer.Name .. ")"
break
end
end
StatusValue.Value = "The " .. winner .. " won the game!"
local winSounds = {
Murderer = ReplicatedStorage:FindFirstChild("MurdererWinSound"),
Innocents = ReplicatedStorage:FindFirstChild("InnocentsWinSound")
}
StatusValue.Value = "The " .. winner .. " won the game!"
-- Play the corresponding win sound
if winner:match("Murderer") and winSounds.Murderer then
winSounds.Murderer:Play()
elseif winner == "Innocents" and winSounds.Innocents then
winSounds.Innocents:Play()
end
task.wait(5)
for _, plr in ipairs(Players:GetPlayers()) do
plr:LoadCharacter()
end
newMap:Destroy()
end