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

Code Duplicates Values and Model again on Death?

Asked by 4 years ago
Edited 4 years ago

So im having this issue, When you join the game all of it seems fine, then whenever you die, When you respawn, The values And model duplicate??? how do i fix this? and it dupicates it 2 times more! (basically dupes of each value and model) on each death! help!

    local copystand = stand:Clone()
    copystand.Parent = chr
    local horp = copystand["StandHumanoidRootPart"]

    local block = game:GetService("ServerStorage")["Block"]
    local copyblock = block:Clone()
    copyblock.Parent = chr

    local blockreduction = game:GetService("ServerStorage")["BlockReduction"]
    local copyblockreduction = blockreduction:Clone()
    copyblockreduction.Parent = chr
    copyblockreduction.Value = blockvalue

    local disabled = game:GetService("ServerStorage")["Disabled"]
    local copydisabled = disabled:Clone()
    copydisabled.Parent = chr

    local deflect = game:GetService("ServerStorage")["Deflect"]
    local copydeflect = deflect:Clone()
    copydeflect.Parent = chr

    local dodge = game:GetService("ServerStorage")["Dodge"]
    local copydodge = dodge:Clone()
    copydodge.Parent = chr

    local rtz = game:GetService("ServerStorage")["RTZ"]
    local copyrtz = rtz:Clone()
    copyrtz.Parent = chr

1 answer

Log in to vote
0
Answered by
Glacitron 239 Moderation Voter
4 years ago

Well obviously, looking at your script you can see that everytime the person dies, the script runs again, meaning everything would get duplicated again, the way to fix this is to check if the object exists before cloning it.

local CheckForRtz = chr:FindFirstChild("RTZ")
if CheckForRtz then return end
elseif not CheckForRtz then
    local rtz = game:GetService("ServerStorage")["RTZ"]
    local copyrtz = rtz:Clone()
    copyrtz.Parent = chr
end

I obviously only wrote it for one of those objects so just follow the same pattern for the others. If this helped you solve your problem please mark this as the answer! :)

0
would i do this for copy stand also BrandonXYZ9 18 — 4y
0
Thanks anyways it worked! BrandonXYZ9 18 — 4y
0
No problem :) Glacitron 239 — 4y
Ad

Answer this question