#Script not working

5 messages · Page 1 of 1 (latest)

regal heart
#

-- module script

function Imessages:ToggleMessage()
-- Determine which message to show based on enabled flags
local messageToShow = message1Enabled and Message1 or (message2Enabled and Message2)
if not messageToShow then return end -- Exit if neither message is enabled

if isMessageVisible then
    messageToShow.Visible = false
    messageToShow.ZIndex = defaultZIndex -- Reset ZIndex when hidden
    BlurEffect.Enabled = false -- Disable blur when message is hidden
    game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
    print("Hiding message") -- Debugging
else
    messageToShow.Visible = true
    messageToShow.ZIndex = activeZIndex -- Set higher ZIndex when shown
    ViewMessage.Visible = false -- Hide the "View Message" button after viewing the message
    BlurEffect.Enabled = true -- Enable blur when message is visible
    game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
    print("Showing message") -- Debugging
end
isMessageVisible = not isMessageVisible -- Toggle the visibility state

end

-- local script

local Imessages = require(game:GetService("ReplicatedStorage").ModuleScript)

-- Show "Jaylen Brown" message
Imessages:NameAndSet("Jaylen Brown", 2) -- Set sender and number of messages
Imessages:EnableMessage1() -- Enable Message1 for toggling
Imessages:ShowMessage(3) -- Show notification for Message1 with a 3-second display time

-- Wait before switching to the next message
task.wait(5)

-- Show "Dad" message
Imessages:NameAndSet("Dad", 3) -- Set sender and number of messages
Imessages:EnableMessage2() -- Enable Message2 for toggling
Imessages:ShowMessage(3) -- Show notification for Message2 with a 3-second display time

basically the message doesnt become visible

if i press q there is a message system an it doesnt become visible (only for message 2) but for message 1 i press q its visible please note only can be visible when function called and Q pressed

tacit cargo
#

local Imessages = {}
local message1Enabled = false
local message2Enabled = false
local isMessageVisible = false

local Message1 = Instance.new("TextLabel") -- Create Message1 instance (replace with your UI)
local Message2 = Instance.new("TextLabel") -- Create Message2 instance (replace with your UI)
local BlurEffect = Instance.new("BlurEffect") -- Replace with your actual blur effect
local defaultZIndex = 1
local activeZIndex = 2

function Imessages:NameAndSet(senderName, messageNumber)
if messageNumber == 1 then
Message1.Text = senderName
elseif messageNumber == 2 then
Message2.Text = senderName
end
end

function Imessages:EnableMessage1()
message1Enabled = true
end

function Imessages:EnableMessage2()
message2Enabled = true
end

function Imessages:ToggleMessage()
local messageToShow = message1Enabled and Message1 or (message2Enabled and Message2)
if not messageToShow then return end -- Exit if neither message is enabled

if isMessageVisible then
    messageToShow.Visible = false
    messageToShow.ZIndex = defaultZIndex -- Reset ZIndex when hidden
    BlurEffect.Enabled = false -- Disable blur when message is hidden
    game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
    print("Hiding message") -- Debugging
else
    messageToShow.Visible = true
    messageToShow.ZIndex = activeZIndex -- Set higher ZIndex when shown
    BlurEffect.Enabled = true -- Enable blur when message is visible
    game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
    print("Showing message") -- Debugging
end
isMessageVisible = not isMessageVisible -- Toggle the visibility state

end

return Imessages

#

Make sure your local script correctly handles the key press to toggle the message visibility:

#

local UserInputService = game:GetService("UserInputService")
local Imessages = require(game:GetService("ReplicatedStorage").ModuleScript)

-- Function to handle key press
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode.Q then
Imessages:ToggleMessage()
end
end)

-- Show "Jaylen Brown" message
Imessages:NameAndSet("Jaylen Brown", 1) -- Set sender and number of messages
Imessages:EnableMessage1() -- Enable Message1 for toggling
Imessages:ToggleMessage() -- Show Message1 immediately

-- Wait before switching to the next message
task.wait(5)

-- Show "Dad" message
Imessages:NameAndSet("Dad", 2) -- Set sender and number of messages
Imessages:EnableMessage2() -- Enable Message2 for toggling
Imessages:ToggleMessage() -- Show Message2 after waiting

#

Correctly Reference Messages: Ensure that Message1 and Message2 are properly initialized and set to your actual UI elements.

Visibility Logic: The ToggleMessage function should check which message is enabled and show or hide it accordingly.

Key Press Handling: The local script should listen for the "Q" key press to toggle the message display.

Debugging: Use print statements to confirm which branch of the logic is being executed, especially in the ToggleMessage function.

UI Initialization: Make sure your UI elements (like Message1) are set up correctly in the game so that they can be manipulated as expected.