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

MouseClick even isn't working right?

Asked by 6 years ago

I'm using this script to get the tween to play when a part is clicked, but for some reason I have to double click the part for it to work. Is there a way to get it working with just one click?

local clickdetector = game.Workspace.D1.ClickDetector
clickdetector.MouseClick:Connect(function()
    tweenUp:Play()
    wait(1)
        clickdetector.MouseClick:Connect(function()
            tweenDown:Play()
        end)
end)

3 answers

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

I'm assuming that you have two function local function tweenUp() --tween here-- end and local function tweenDown() --tween here-- end Well if you did have two functions, then you are calling it incorrectly. It's supposed to be tweenUp() and tweenDown if you want a function to be called Always remember that code is gonna be ran from the top to the final line of code, Also make sure that your script is a Global Script, not a local script(That is very important!) Here's an example

print("Hi") -- Executes first
wait(1)-- Executes next
print("Bye")--Executes last

Same thing with events! So if you clicked on something, Everything in that event will be done Then you do the next event

local clickdetector = game:GetService(Workspace):FindFirstChild("D1"):FindFirstChild("ClickDetector") -- Finds Workspace,D1 and Click Detector(aka the same way to type in game.Workspace.D1.ClickDetector)
local function tweenUp() 
    --tween--
end
local function tweenDown()
    --tween
end
clickdetector.MouseClick:Connect(function() -- Click to tween up
    tweenUp()
end)
 clickdetector.MouseClick:Connect(function() -- Click again to tween down
           tweenDown()
end)

If you wanted to do it all in one click you would do something like this

local function tweenUp() 
    --tween--
end
local function tweenDown()
    --tween
end
clickdetector.MouseClick:Connect(function() -- Click to tween up and tween down
     tweenUp()
    wait(1)
    tweenDown()
end)

Hopefully this is a great explanation of how to fix this

Ad
Log in to vote
0
Answered by
Asceylos 562 Moderation Voter
6 years ago

By just removing the second function.

local clickdetector = game.Workspace.D1.ClickDetector
clickdetector.MouseClick:Connect(function()
    tweenUp:Play()
    wait(1)
            tweenDown:Play()
end)

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

The way to make it 1 click is by removing the second function.

EDIT: I realized my mistake because I was in a rush. Sorry.

0
not even.. greatneil80 2647 — 6y

Answer this question