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

On Click Destroy Parent? Very Confused Scripter

I Am Trying To Make A Block That When You Click It It Gives You Cash And Destroys Itself. I Already Have It So It Gives You Cash, I Just Need The Destroy

script.Parent.ClickDetector.MouseClick:connect(function(player) local players = game.Players:FindFirstChild(player.Name) local clicks = players:FindFirstChild("leaderstats")["Money"] clicks.Value = clicks.Value + 150 click.MaxActivatoinDistance = 0 wait (5) click.MaxActivatoinDistance = 5 end)
script.Parent.ClickDetector.MouseClick:connect (Parent destroy)

2 comments

0

lmao ur grammar is bad, and so is your spelling

0

Imao You Should Be Reported For Bullying. Imao That Jerk.

3 answers

✓ Accepted answer

I just wanna say, please do some research before you ask a question, cause the mistake is kinda whack.

First of all, try to clean up your script so you can read it easily:

local clickDetector = script.Parent.ClickDetector

clickDetector.MouseClick:Connect(function(player)
    local clicks = player.leaderstats.Money
    clicks.Value = 150
    clickDetector.MaxActivationDistance = 0 
    wait(5)
    clickDetector.MaxActivationDistance = 5
end)

script.Parent.ClickDetector.MouseClick:Connect(Parent destroy)

. .

script.Parent.ClickDetector.MouseClick:Connect(Parent destroy)

It's best to note the thing in the parenthesis is a parameter, and you cannot use regular words in it, you must use a Lua type.

So, you could make the parent nil (nothing) by typing:

local function gone() 
 --whatever the block is
	part.Parent = nil
end

 script.Parent.ClickDetector.MouseClick:Connect(gone)

Now just put that at the end of the script and your finished. Hope you learned something!

--------[[Defining Players]]--------------
local Players = game:GetService("Players")

--------[[Defining ClickDetector]]-------------
local clicker = script.Parent.ClickDetector
	clicker.MaxActivationDistance = 0
	wait(5)
	clicker.MaxActivationDistance = 5

---------[[Set up the anti-spam click]]-----------
local debounce = true

---------[[Wrapping the outcome in the click function]]------------
clicker.MouseClick:Connect(function(player)
	
	---------[[tell the function that it's already clicked so clicking it multiple more times won't do anything else]]----------
	if debounce then
		debounce = false
		
		-------[[Defining the money]]------------
		local clicks = player:FindFirstChild("leaderstats"):FindFirstChild("Money")
		
		--------[[tell what the outcome is]]--------
		clicks.Value = clicks.Value + 150
		
	------[[wait in seconds before doing the next step]]------	
	wait(5)
	
	-------[[Destroy the part]]---------
	script.Parent:Destroy()
	
	-----[[Ends the anti-spam click]]-----
	end

---------[[Ends the click function]]--------	
end)

1 comment

0

the spacing and indentation makes me wanna vomit

script.Parent.ClickDetector.MouseClick:connect(function()
	script.Parent:destroy()
end

( Parent destroy )

1 comment

0

fun fact: :destroy() is deprecated

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