Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to fix destroy functions that are cloned?

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

2 comments

0

Swap the "or" around on line 7.

0

You spelt Destroy wrong, it should be spelt "Destroy". Just a simple mistake :)

1 answer

✓ Accepted answer

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)

2 comments

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

0

It should be able to work now. I edited it.

This discussion is preserved as it was. New answers, comments, and votes are closed.