Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

im making a game where if you click three things a door opens and the script wont work. why?

Asked by 5 months ago
Edited 5 months ago

im making a game where if you click three things a door opens and the script wont work. ive found where the bug is and its that the if script wont work. anyway here is the code:

here is link https://pastebin.com/gDtz43ew

0
That's because it only checks once, and immediately when you start the game. Ziffixture 5732 — 5mo
0
ok but how do you make it check when its been done cjkizzy286 24 — 5mo
0
I'd wrap it in a function and use it within each signal callback for a quick solve. Ziffixture 5732 — 5mo
0
You can also enclose your code in a Lua Code Block, instead of giving a paste in link. Either that or at least make it a hyperlink for convince. Ziffixture 5732 — 5mo

1 answer

Log in to vote
0
Answered by 5 months ago

This part is your problem:

if book1 == 2 and leg1 == 2 and thing == 2 then
    game.Workspace.Part1mo.Position = Vector3.new(120.312, 12.125, -19.625)
    wait(5)
    game.Workspace.Part1mo.Position = Vector3.new(120.312, 4.625, -19.625)
    book1 = 1
    leg1 = 1
    thing = 1
end

It only runs once, you would have to run that code block every time one of the ClickDetectors is triggered. You could do that by wrapping it into a function like so:

function CheckStatus()
    if book1 == 2 and leg1 == 2 and thing == 2 then
        game.Workspace.Part1mo.Position = Vector3.new(120.312, 12.125, -19.625)
        wait(5)
        game.Workspace.Part1mo.Position = Vector3.new(120.312, 4.625, -19.625)
        book1 = 1
        leg1 = 1
        thing = 1
    end
end

And then add this function to the click detectors as follows:


script.Parent.MouseClick:Connect(function() thing = 2 CheckStatus() end) book.ClickDetector.MouseClick:Connect(function() book1 = 2 CheckStatus() end) leg.ClickDetector.MouseClick:Connect(function() leg1 = 2 CheckStatus() end)
0
thanks this is very helpful cjkizzy286 24 — 5mo
Ad

Answer this question