Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
CodyDev 70
6 years ago

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

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. RAYAN1565 691 — 6y
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. CodyDev 70 — 6y
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? User#1007 6 — 6y
1
Can you post the code? RAYAN1565 691 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
0
This is the exact same thing that I did, except this doesn't even put the armor on the character. CodyDev 70 — 6y
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. Meltdown81 309 — 6y
0
Also please state whether you're armor is an accessory or you're just welding it onto the player's character. Meltdown81 309 — 6y
Ad

Answer this question