Morph is limited to one player

  1. Hi, the intent is to change the model of each player that triggers the proximity prompt, currently it will only allow one and stops working thereafter.

  2. https://gyazo.com/0b6b7a0c0decfdd0e37f9bc56e276909

  3. I’ve modified @PseudoPerson’s morph proximity pack to set the players character to a model in server storage opposed to the original which was based on HumanoidDescription.

-- Morph Script

local ProximityPrompts = script["Proximity Prompts"]

local Morph = game.ServerStorage.MorphCharacter:Clone()

local proximityPrompts = {}
local connections = {}

local function getProximityPrompts()
	for index, child in pairs(ProximityPrompts:GetChildren()) do
		if child:IsA("ObjectValue") then
			local prompt = child.Value
			if prompt:IsA("ProximityPrompt") then
				table.insert(proximityPrompts, prompt)
			end
		end
	end
end

local function onTriggered(player)
	local character = player.Character
	if character then
		local humanoid = character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			Morph.Name = player.Name
			player.Character = Morph
			Morph.Parent = workspace
		end
	end
end

getProximityPrompts()
for index, prompt in ipairs(proximityPrompts) do
	local connection = prompt.Triggered:Connect(onTriggered)
	table.insert(connections, connection)
end
player.Character = Morph:Clone()

Simply clone the morph and that should fix your problem.

As @dukzae said you aren’t cloning the morph which makes it so there is only 1 morph inside the game. Use :Clone() function to fix your problem.

That resulted in another strange issue. It cloned the model in the workspace, but the player is no longer in control of it.

https://gyazo.com/50c2a3fca460a58b5b6922ec057ebd10

u would have to use LoadCharacter() so the new character u just changed loads in
https://developer.roblox.com/en-us/api-reference/function/Player/LoadCharacter

You can also fix that by killing the player but thats the efficient way.

How would I implement LoadCharacter() into my script above? I’ve done so unsuccessfully; it respawns my character without changing its model.

-- Morph Script

local ProximityPrompts = script["Proximity Prompts"]

local Morph = game.ServerStorage.MorphCharacter:Clone()

local proximityPrompts = {}
local connections = {}

local function getProximityPrompts()
	for index, child in pairs(ProximityPrompts:GetChildren()) do
		if child:IsA("ObjectValue") then
			local prompt = child.Value
			if prompt:IsA("ProximityPrompt") then
				table.insert(proximityPrompts, prompt)
			end
		end
	end
end

local function onTriggered(player)
	local character = player.Character
	if character then
		local humanoid = character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			Morph.Name = player.Name
			player.Character = Morph
			Morph.Parent = workspace
            player:LoadCharacter()
		end
	end
end

getProximityPrompts()
for index, prompt in ipairs(proximityPrompts) do
	local connection = prompt.Triggered:Connect(onTriggered)
	table.insert(connections, connection)
end

try this

This should work:

local ProximityPrompts = script["Proximity Prompts"]


local proximityPrompts = {}
local connections = {}

local function getProximityPrompts()
	for index, child in pairs(ProximityPrompts:GetChildren()) do
		if child:IsA("ObjectValue") then
			local prompt = child.Value
			if prompt:IsA("ProximityPrompt") then
				table.insert(proximityPrompts, prompt)
			end
		end
	end
end

local function onTriggered(player)
	local character = player.Character
	if character then
        local Morph = game.ServerStorage.MorphCharacter:Clone()
		local humanoid = character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			Morph.Name = player.Name
			player.Character = Morph
			Morph.Parent = workspace
		end
	end
end
getProximityPrompts()
for index, prompt in ipairs(proximityPrompts) do
	local connection = prompt.Triggered:Connect(onTriggered)
	table.insert(connections, connection)
end
1 Like

Thank you so much for your time!

The problem is that the Morph variable was outside the Triggered local function, so I put the Morph variable in the Triggered local function and no problem!

1 Like