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
1 | 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 ) |
2 | script.Parent.ClickDetector.MouseClick:connect (Parent destroy) |
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:
01 | local clickDetector = script.Parent.ClickDetector |
02 |
03 | clickDetector.MouseClick:Connect( function (player) |
04 | local clicks = player.leaderstats.Money |
05 | clicks.Value = 150 |
06 | clickDetector.MaxActivationDistance = 0 |
07 | wait( 5 ) |
08 | clickDetector.MaxActivationDistance = 5 |
09 | end ) |
10 |
11 | script.Parent.ClickDetector.MouseClick:Connect(Parent destroy) |
. .
1 | 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:
1 | local function gone() |
2 | --whatever the block is |
3 | part.Parent = nil |
4 | end |
5 |
6 | script.Parent.ClickDetector.MouseClick:Connect(gone) |
Now just put that at the end of the script and your finished. Hope you learned something!
01 | --------[[Defining Players]]-------------- |
02 | local Players = game:GetService( "Players" ) |
03 |
04 | --------[[Defining ClickDetector]]------------- |
05 | local clicker = script.Parent.ClickDetector |
06 | clicker.MaxActivationDistance = 0 |
07 | wait( 5 ) |
08 | clicker.MaxActivationDistance = 5 |
09 |
10 | ---------[[Set up the anti-spam click]]----------- |
11 | local debounce = true |
12 |
13 | ---------[[Wrapping the outcome in the click function]]------------ |
14 | clicker.MouseClick:Connect( function (player) |
15 |
1 | script.Parent.ClickDetector.MouseClick:connect( function () |
2 | script.Parent:destroy() |
3 | end |
( Parent destroy )