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

How to make players respawn with certain meshes?

The problem i have with this is they spawn with the correct meshes (I have inside serverstorage that gets cloned to the players character) but when they respawn it doesn't add it to them. The problem only occurs for players who have character meshes. If somebody doesnt have meshes then when they respawn they get given the meshes I have. If they have meshes for their character (such as robloxian 2.0, etc) then it just loads them as theirselves.

Is there a way to wait for their own meshes to load, then remove them? Or to make it so every player doesnt have a mesh, but they keep their clothing, hats, etc.?

2 answers

You have to clone the Mesh everytime they respawn:

--Put this script in ServerScriptStorage

local Storage = game:GetService('ServerStorage')
local Mesh = Storage:WaitForChild("My Mesh")
game.Players.PlayerAdded:connect(plr)
	plr.CharacterAdded:connect(char)
		local NewMesh = Mesh:Clone()
		NewMesh.Parent = char.SomeWhere
	end)
end)

1 comment

0

Thats what im doing. The problem is it clones the mesh into the player, then the players normal meshes are created, thus removing the ones i put in the player. I need a way to wait for the players original meshes to load before giving them the ones i have stored

You can add a whitelist.


local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local character = player.Character or player.CharacterAdded:wait()
local banned = 'CharacterMesh'
local meshes = ReplicatedStorage:WaitForChild('Folder')

local whiteList = {
	meshname1 = true, 
	meshname2 = true, 
	meshname3 = true
}

--[[ this has the potential to fail because of you loading before the objects
for i,v in pairs(meshes:GetChildren()) do
	-- populate
	whiteList[v.Name] = v
end
--]]

function delete(obj)
    if obj.ClassName == banned or obj.Name == banned then
		if not whiteList[obj.Name] then 
	        game.Debris:AddItem(obj, 1/30)
	        print("Deleted: " ..obj.Name)
		end
    end
end

character.DescendantAdded:connect(function(obj)
	-- If anything gets added as we load or after, check it. 
    delete(obj)
end)

-- if the script loads after we load for whatever reason
-- loops through every Instance in character

local function recur(obj)
	for i,v in pairs(obj:GetChildren()) do
		delete(v)
		recur(v)
	end
end

recur(character)

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