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

Code Duplicates Values and Model again on Death?

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

✓ Accepted answer

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! :)

3 comments

0

would i do this for copy stand also

0

Thanks anyways it worked!

0

No problem :)

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