So I have this simple script that when OnTouched duplicates the scripts from within my model into your Character, pretty simple. The problem I am having concerns the script duplication from within your character itself. It tends to cause lag as more than one of each script can be found from within your Character, which is a big problem on my part. I get this isn't a request site but is there any possible way of stopping my scripts from stacking without completely disabling the OnTouched script or removing the base part? Help would be amazing on my part! :)
(I know the answer is obvious but I just cant seem to see it)
Here's the script I am having issues with:
Part = script.Parent debounce = false function onTouch(hit) local human = hit.Parent:FindFirstChild("Humanoid") if (human ~= nil) then wait(1) Part["MG"]:clone().Parent = hit.Parent Part["SSE"]:clone().Parent = hit.Parent Part["SSQ"]:clone().Parent = hit.Parent Part["AA"]:clone().Parent = hit.Parent Part["R"]:clone().Parent = hit.Parent Part["RR"]:clone().Parent = hit.Parent end end script.Parent.Touched:connect(onTouch)
(Don't mind the script abbreviations, I know I'm messy with them)
What I would recommend doing is checking if one of the scripts can actually be found inside the part. Since all of the scripts are being duplicated at the same time, if one is there, the rest of them have to be there also!
So here is your revised script:
Part = script.Parent debounce = false function onTouch(hit) local human = hit.Parent:FindFirstChild("Humanoid") if (human ~= nil) then if hit.Parent:FindFirstChild'MG' == nil then wait(1) Part["MG"]:clone().Parent = hit.Parent Part["SSE"]:clone().Parent = hit.Parent Part["SSQ"]:clone().Parent = hit.Parent Part["AA"]:clone().Parent = hit.Parent Part["R"]:clone().Parent = hit.Parent Part["RR"]:clone().Parent = hit.Parent else -- This is not necessary, but it will inform you print('Script is already in '..hit.parent.Name..'!') end end end script.Parent.Touched:connect(onTouch)