Edit: After some more looking around I found the source of the problem, this script is being spawned in by another script (it is a tycoon and the first button enables this second button), the first script is spawning this model in as a child of it, messing up the parent system. Does anyone know how I can fix this?
I am making a tycoon game and currently setting up purchase buttons and upgraders. Here is the code I am getting the error in:
local cost = 600 local model = script.Parent.Parent.Parent.Parent.Upgrader2
local newmodel = model:clone()
wait(1)
model:remove() owner = script.Parent.Parent.Parent.Parent.Parent.Owner local debounce = false
function onTouched(p) if debounce == false then debounce = true if p.Parent:findFirstChild("Humanoid") ~= nil then if owner.Value == p.Parent.Name then local player = game.Players:FindFirstChild(p.Parent.Name) local stats = player:findFirstChild("leaderstats") if stats ~= nil then local cash = stats:findFirstChild("Money") if cash.Value >= cost then cash.Value = cash.Value - cost newmodel.Parent = script.Parent.Parent.Parent script.Parent.Parent:remove() end end end end debounce = false end end
script.Parent.Touched:connect(onTouched)
The error line is "local model = script.Parent.Parent.Parent.Parent.Upgrader2"

3 comments
make sure you didn't add too many .Parent 's
Use the lua code block next time.
Torren_Mr What do you mean by that?