Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Attempt to Index Function with Destroy?

Asked by 4 years ago

I am trying to make a prop regenning script, and whenever it regens an error saying Attempt to index function with destroy. The error is at line 8.

local regenScript = script
local ServerStorage = game:GetService("ServerStorage")
local Workspace = game:GetService("Workspace")
local regenProps = Workspace:WaitForChild("AllProps")
local save = regenProps:Clone()

local function regenProps()
    regenProps:Destroy()
    local newSave = save:Clone()
    newSave.Parent = Workspace
    newSave:MakeJoints()
end

while true do 
    wait(180) 
    regenProps()
end

2 answers

Log in to vote
2
Answered by
Rheines 661 Moderation Voter
4 years ago
Edited 4 years ago

It didn't work because you've overridden the regenProps model with the function regenProps. Simply changing one of the variable's names will work. You don't need to clone the model at the beginning of the script. You also don't need to declare workspace as a variable.

local regenScript = script
local ServerStorage = game:GetService("ServerStorage")
local Props = Workspace:WaitForChild("AllProps")

local function regenProps()
    local new = Props:Clone()
    Props:Destroy()
    Props = new
    Props.Parent  = workspace
    Props:MakeJoints()
end

while true do 
    wait(180) 
    regenProps()
end
Ad
Log in to vote
4
Answered by 4 years ago
Edited 4 years ago

The problem here is you need to either change the function name regenProps() or change the name of the variable local regenProps to something else

1
Accept if it helped :D Nguyenlegiahung 1091 — 4y
0
Thanks! youtubemasterWOW 2741 — 4y

Answer this question