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

On Click Destroy Parent? Very Confused Scripter

Asked by 4 years ago

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)
0
lmao ur grammar is bad, and so is your spelling LoganboyInCO 150 — 4y
0
Imao You Should Be Reported For Bullying. Imao That Jerk. ricelicker 52 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago
Edited by User#24403 4 years ago

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!

Ad
Log in to vote
0
Answered by 4 years ago
--------[[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)
0
the spacing and indentation makes me wanna vomit LoganboyInCO 150 — 4y
Log in to vote
0
Answered by 4 years ago
script.Parent.ClickDetector.MouseClick:connect(function()
    script.Parent:destroy()
end

( Parent destroy )

0
fun fact: :destroy() is deprecated LoganboyInCO 150 — 4y

Answer this question