Module script help

I have this module script:

local module = {}

local module = {}

local Thoughts1 = {"I never undestood why they have these scans", "I mean know why they are done...", "they say it is to keep me safe.", "Obviously what they really want is to have their chance to spy on me 3 times a day...", "But at that point why just not have those cameras down at all times?", "They care so much about me being visible those 3 times a day...", "why would they not just give themselves the means to be spying on me 24/7?", "Yet again, I'm not complaining.", "The less time those cameras are aimed at me the better."}
local Thoughts2 = {"Random stuff", "Random stuff1", "Random stuff2," , "Random stuff3", "Random stuff4"}

local CompletedDialogues = {}

module.Thoughts1 = Thoughts1
module.Thoughts2 = Thoughts2

local CurrentDialogue = 1

function module.Think(Thought, Player, Jumpstart)
    if CompletedDialogues[Thought] ~= nil then return end
    print('started')
    print(CurrentDialogue)
    Player.PlayerGui.Thoughts.Frame.Visible = true
    print("got to here")
    if Jumpstart and CurrentDialogue == 1 then CurrentDialogue = 2 end
    local ThoughtTable = module["Thoughts"..Thought]
    if ThoughtTable[CurrentDialogue] then
        print(ThoughtTable[CurrentDialogue])
        Player.PlayerGui.Thoughts.Frame.TextLabel.Text = ThoughtTable[CurrentDialogue]
        game.SoundService.Notification:Play()
        CurrentDialogue += 1 
    else
        print('dialogue does not exist')
        CompletedDialogues[Thought] = true
        Player.PlayerGui.Thoughts.Frame.Visible = false
        CurrentDialogue = 1
    end

end


return module

server:

game.Players.PlayerAdded:Connect(function(playerAdded)
	playerAdded.CharacterAdded:Connect(function(char)
		player = playerAdded
		character = char
		
		local newThing = Instance.new("NumberValue", player)
		newThing.Name = "ThinkingNumber"
		newThing.Value = 1
		ThoughtsModule.Think(1, player)
		task.wait(5)
		
		game.ReplicatedStorage.ThinkVisible:FireClient(playerAdded)
		player:FindFirstChild("ThinkingNumber").Value = 2
		ThoughtsModule.Think(2, player)
		task.wait(10)
		character.Humanoid.WalkSpeed = 0
	end)
end)

local:

local ThoughtsModule = require(game.ReplicatedStorage:WaitForChild("ThoughtsModules"):WaitForChild("Thoughts"))
local UIS = game:GetService("UserInputService")

local player = game.Players.LocalPlayer

UIS.InputBegan:Connect(function(input)
	if input and input.KeyCode == Enum.KeyCode.E then
		if player:FindFirstChild("ThinkingNumber") then
			print(player:FindFirstChild("ThinkingNumber").Value)
			ThoughtsModule.Think(player:FindFirstChild("ThinkingNumber").Value, player, "Jumpstart")
			print("fired module")
		end
	end
end)

game.ReplicatedStorage.ThinkVisible.OnClientEvent:Connect(function()
	player.PlayerGui.Thoughts.Frame.Visible = true
end)

the issue is after the server script calls the function for the second time it immediately goes to the SECOND dialogue in the correct table, printing the current dialogue value shows 2 but whys that when i literally reset it inside the module script?

Now I used an AI to debug it and it told me why it was doing that and fixed the code and it works now but its explanation made 0 sense, it was talking about the variable being global across all instances of the module or something. Which if the variable is global then cool. Its a single player game anyways and if its global wouldn’t it be globally one everywhere, why is it on the second call of the module 2 despite being reset…?

1 Like