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

The script of Click Detector only works ones, why?

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!

2 comments

0

Is it a server or local script? And btw mouseClick is deprecated so use MouseClick

0

a script

1 answer

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

4 comments

0

but question, how can I made the clickdetector disappear and reappear?

0

ah I see, let me edit my answer

0

ah I see, let me edit my answer

0

This may work, not 100% if it doesnt work, put it in a while loop

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