Hi, so I’m trying to make a feature in my game where you use a proximity prompt to buy a gas mask for all players, and I have a script to morph the player into a model with the gas mask. Problem is, I don’t know how to apply this to all players in the lobby. If anyone can figure this out, I would appreciate it!
local model = script.Parent
local prompt = model.Prompt.ProximityPrompt
prompt.Triggered:Connect(function(player)
local oldCharacter = player.Character
local morphModel = model:FindFirstChildOfClass("Model")
local newCharacter = morphModel:Clone()
newCharacter.HumanoidRootPart.Anchored = false
newCharacter:SetPrimaryPartCFrame(oldCharacter.PrimaryPart.CFrame)
player.Character = newCharacter
newCharacter.Parent = workspace
end)
(The Code Review category is for code feedback rather than solving problems)
Just loop through all the players
local model = script.Parent
local prompt = model.Prompt.ProximityPrompt
prompt.Triggered:Connect(function()
for _, player in game.Players:GetPlayers() do -- loop through all the players
local oldCharacter = player.Character
local morphModel = model:FindFirstChildOfClass("Model")
local newCharacter = morphModel:Clone()
newCharacter.HumanoidRootPart.Anchored = false
newCharacter:SetPrimaryPartCFrame(oldCharacter.PrimaryPart.CFrame)
player.Character = newCharacter
newCharacter.Parent = workspace
end
end)
Hello! I would like to share an updated version of your same idea but in a more modular and adaptable way:
local function applyGasMaskMorph(player, model)
local oldCharacter = player.Character
local morphModel = model:FindFirstChildOfClass("Model")
local newCharacter = morphModel:Clone()
newCharacter.HumanoidRootPart.Anchored = false
newCharacter:SetPrimaryPartCFrame(oldCharacter.PrimaryPart.CFrame)
player.Character = newCharacter
newCharacter.Parent = workspace
end
local model = script.Parent
local prompt = model.Prompt.ProximityPrompt
prompt.Triggered:Connect(function(player)
for _, player in ipairs(game.Players:GetPlayers()) do
applyGasMaskMorph(player, model)
end
end)