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

How to use a new Clone:() of a model each time a script runs?

I have a server script that checks the name of every player that joins the game. If their name is CodyDev (me) it gives them armor. The armor is given to them by using this:

local armor = game.ServerStorage["Armor"]:Clone()

The problem I am having is that if the player dies, when they respawn it uses the same clone and therefore all the parts are broken. Instead, I want to use a new clone for every time the script runs, so it does not break. How would I go about doing this?

Image of broken armor

4 comments

0

You need to somehow figure out a way to identify when the character is dying and is re-spawning. Then disable the script for a period of time until the character respawns. When the character respawns, then enable the script.

0

I used a local script that tells the server when the player dies and then disables the script for 2 seconds. This caused the script to stop working, it didn't error but my character did not spawn with any armor again.

0

Have you tried just putting the armor in Server Storage or some other place and cloning from there, instead of cloning the already used one?

1

Can you post the code?

1 answer

Storing objects that are gonna be used in the client in ServerStorage isn't a good idea. Anyway see if this works for you.

--ServerScriptStorage-->Script
local ply = nil
local armorRoot = game.ReplicatedStorage.Armor
local admins = {
	"CodyDev" = true,
	"AdminName" = true
}

game.Players.PlayerAdded:connect(function(player)
	if admins[player.Name] then
		player.CharacterAdded:connect(function(cha)
			local armor = armorRoot:Clone()
			armor.Parent = cha	--When the character dies the armor is destroyed as well
			armor:MakeJoints()
		end)
	end
end)

3 comments

0

This is the exact same thing that I did, except this doesn't even put the armor on the character.

0

I was under the assumption you already had code to put armor on the character since you didn't ask. Provide all of the script relating to the problem instead of one line of code next time.

0

Also please state whether you're armor is an accessory or you're just welding it onto the player's character.

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