Issue with localscripts (that I presume are core scripts)

For some reason, Whenever this script is enabled, roblox core scripts begin spamming random part names from workspace and “rendered” in the output. this also drops the game to a crawling 0.4 fps, so its pretty important i figure out why. script below:

local Players = game.Players
local box = script.Parent
local plr = Players.LocalPlayer
local id = plr.UserId
local plrM = plr.Character
local stat = plr:WaitForChild("Stats")
local hats = stat:FindFirstChild("Hats")
local rep = game.ReplicatedStorage
local templates = rep:WaitForChild("Templates")
local tem = templates:FindFirstChild("hatUItem")
local hatMs = rep:FindFirstChild("HatsModels")

local function Add(child)
	if child:IsA("StringValue") then
		local c = tem:Clone()
		c.Parent = box
		local index = child:GetAttribute("Index")
		local hat = child.Value
		c.Name = index
		if hatMs:FindFirstChild(hat) then
			c:FindFirstChild("Name").Text = hat
			local r = hatMs:FindFirstChild(hat):Clone()
			print(c.Name)
			r.Parent = c
			local sc = templates:FindFirstChild("thing"):Clone()
			print(r.Name)
			sc.Parent = r
			sc.Enabled = true
		end
	end
end

local function Removed(child)
	local index = child:GetAttribute("Index")
	if child:IsA("StringValue") then
		for i,v in box:GetChildren() do
			if v.Name == index then v:Destroy() end
		end
	end
end

hats.ChildAdded:Connect(Add)
hats.ChildRemoved:Connect(Removed)
1 Like

You have used “rep” as your variable name for replicatedStorage, and “rep” is a keyword.
string | Roblox Creator Documentation

That’s not a keyword, but a key in a table. The crappy Lua highlighting that the forum uses still highlights those like they’re special, but they aren’t.

@Th1v5
What is the exact output you’re talking about?

ive been using rep as my replicatedstorage name since i started coding, and this is the only time the error has occuredd

it goes through every part name (Not in a table, indivually) and prints the name, then rendered. I think this is a bug in the rendering engine, as the game does not render in 3D either.

Alright. I got new info, the error occurs in the “Add” function.

i still dont know how to fix it though, is it firing when it shouldnt or what?

Alright, so I found the error. There was a localscript inside my hatModels that caused the bug, and since the hatModels got cloned, the local scripts came with them. Upon deleting those, everything works again!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.