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

The script of Click Detector only works ones, why?

Asked by 5 years ago
Edited 5 years ago

I have made a Click Detector script but when I finish clicking and when it came back nothing worked why?

local Rock = game.Workspace.Rock
local target = game.ReplicatedStorage.ClickDetector
local TimesClicked = 0
local a = game.Workspace.Rock.ClickDetector.Script
local Click = game.Workspace.Rock.ClickDetector
script.Parent.mouseClick:Connect(function(Player)
TimesClicked = TimesClicked +1
if TimesClicked == 3 and TimesClicked ~= nil then
Player.leaderstats.SpacePieces.Value = Player.leaderstats.SpacePieces.Value +2
script.Parent.Parent.Transparency = 1
script.Parent.Parent.CanCollide = true
a.Parent = game.Workspace.Rock
Click:Destroy()
wait(3)
Rock.Transparency = 0
Rock.CanCollide = false
local ClickDetector = target:Clone()
ClickDetector.Parent = game.Workspace.Rock
end
    end)

Please help!

0
Is it a server or local script? And btw mouseClick is deprecated so use MouseClick User#19524 175 — 5y
0
a script RainbowBeastYT 85 — 5y

1 answer

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

Basically you want a rock to appear and disappear after 3 seconds when you click 3 buttons and give money? Give this a try, it is sample code and is not tested.

And by the way, destroying the object is not very useful, cloning is slightly hard, putting a click detector in a newly made rock probably won't work properly....

local rock = workspace.Rock -- get rock
local Clicker = workspace.Rock.ClickDetector -- get detector
local timesClicked = 0
Clicker.MouseClick:Connect(function(Person)
timesClicked = timesClicked + 1
    if timesClicked >= 3 then
        workspace.Rock.ClickDetector.Parent = game.ReplicatedStorage
        timesClicked = 0
        Person.leaderstats.SpacePieces.Value = Person.leaderstats.SpacePieces.Value + 2
        rock.Transparency = 1
        rock.CanCollide = false
        wait(3)
        rock.CanCollide = true
        rock.Transparency = 0
        workspace.Rock.ClickDetector.Parent = workspace.Rock
    end
end

Since u set the rock already from the start, if you remove it and replicate it, the original rock is still stored in the variable "rock" and you won't be able to do much unless you use a loop. SO try it my way, thanks

0
but question, how can I made the clickdetector disappear and reappear? RainbowBeastYT 85 — 5y
0
ah I see, let me edit my answer greatneil80 2647 — 5y
0
ah I see, let me edit my answer greatneil80 2647 — 5y
0
This may work, not 100% if it doesnt work, put it in a while loop greatneil80 2647 — 5y
Ad

Answer this question