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 5 years ago
Edited 5 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!

01local copystand = stand:Clone()
02copystand.Parent = chr
03local horp = copystand["StandHumanoidRootPart"]
04 
05local block = game:GetService("ServerStorage")["Block"]
06local copyblock = block:Clone()
07copyblock.Parent = chr
08 
09local blockreduction = game:GetService("ServerStorage")["BlockReduction"]
10local copyblockreduction = blockreduction:Clone()
11copyblockreduction.Parent = chr
12copyblockreduction.Value = blockvalue
13 
14local disabled = game:GetService("ServerStorage")["Disabled"]
15local copydisabled = disabled:Clone()
View all 28 lines...

1 answer

Log in to vote
0
Answered by
Glacitron 239 Moderation Voter
5 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.

1local CheckForRtz = chr:FindFirstChild("RTZ")
2if CheckForRtz then return end
3elseif not CheckForRtz then
4    local rtz = game:GetService("ServerStorage")["RTZ"]
5    local copyrtz = rtz:Clone()
6    copyrtz.Parent = chr
7end

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 — 5y
0
Thanks anyways it worked! BrandonXYZ9 18 — 5y
0
No problem :) Glacitron 239 — 5y
Ad

Answer this question