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

How to fix destroy functions that are cloned?

Asked by 7 years ago

I have a clone script in ServerScriptStorage and then I have a part in ServerStorage. The script in ServerScriptStorage is a clone script that clones the part in ServerStorage

This is the script in a ClickDetector and its parent is the part so part to ClickDetector to script

The error in the output says "Destory is not a valid member of Part" error on: Script 'Workspace.GrassBox.ClickDetector.Script', Line 7 This has been cloned to workspace

wait(0.5)
local grassbox = game.Workspace:WaitForChild("GrassBox")

function Clicked(Plr)
    Plr:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value = Plr:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value + 1
    wait(0.1)
    grassbox:Destory()
end


script.Parent.MouseClick:connect(Clicked)

basically problem is grassbox:Destroy() but I don't know how to fix

0
Swap the "or" around on line 7. User#5423 17 — 7y
0
You spelt Destroy wrong, it should be spelt "Destroy". Just a simple mistake :) FiredDusk 1466 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Here is your revised script. Also I just wrote it in a more efficient way in my opinion. Hope it works! If not let me know.

wait(0.5)
local grassbox = game.Workspace:WaitForChild("GrassBox")

script.Parent.MouseClick:connect(function(clicked)
    local chr = clicked.Parent
    local plr = game.Players:GetPlayerFromCharacter(chr)
    if plr:FindFirstChild("leaderstats") then
        if plr.leaderstats:FindFirstChild("GrassTokens") then
            plr.leaderstats.GrassTokens.Value = plr.leaderstats.GrassTokens.Value + 1
        end
    end
    wait(0.1)
    grassbox:Destroy()
end)

0
Doesn't work the problem is "Workspace.GrassBox.ClickDetector.Script:7: attempt to index local 'plr' (a nil value)" on line 7 where plr:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value = plr:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value + 1 is please fix BlackOrange3343 2676 — 7y
0
It should be able to work now. I edited it. TickTockTheory 106 — 7y
Ad

Answer this question