I am making a cutscene with dialoge, but it isn’t working correctly. I have a gui that when pressed the dialoge continues, well when the least dialoge box pops up, I want the cutscene to stop.
this is my current code
local joeVar = 1
if game.Players.LocalPlayer.PlayerGui.DialogueGui.Frame1.TextButton.MouseButton1Click then --this basically just says "when the button that progresses the dialoge is pressed"
joeVar = joeVar + 1
end
if joeVar == 3 then --joeVar is the number of times the player has to click for the cutscene to end therefore i have two Dialoge slides
game.Players.LocalPlayer.PlayerGui.DialogueGui.Frame1.TextButton.MouseButton1Click:Connect(function()
Demo:Stop()
end)
end
the problem is that when I use this script the cutscene doesn’t end when i finish the dialoge gui, but when i turn the joeVar in the if statement into 2 the cutscene ends 1 Dialoge slide too early
I think you mean to do something like this. I’ve added some slight changes (see below)
I’m assuming that Frame1.TextButton is the same button for advancing and completion.
local joeVar = 1
local last = 3
game.Players.LocalPlayer.PlayerGui.DialogueGui.Frame1.TextButton.MouseButton1Click:Connect(function()
joeVar += 1 -- same as joeVar = joeVar + 1
if joeVar == last then
Demo:Stop()
end
end)
If this code is running more than once, it’s really important to disconnect the event once you are finished with it or these events will stack, or cause a memory leak in your game. Ideally you’d have this listener created once, then set joeVar to 1 and last to the amount of dialogs to show.
Here i assume you are trying to check if the mouse has been clicked. If it has, you want to increment joeVar by one. The problem with the code here is that .MouseButton1Click is actually a event, not a boolean (true or false). Your if statement instead is basically seeing if MouseButton1Click exists on TextButton, or isn’t nil.
Therefore, when you run this code it will add 1 to joeVar immediately, as MouseButton1Clickdoes indeed exist on TextButton, but it will only do this once causing the issue you described below.
In summary, your implementation will only add to joeVar once.