Skip to content
TheChatArchiveThe Chat Archive
gpt-4-1106-preview· OpenAIAi2 WildChat-4.8M (AI2)

Create roblox luau script bus annocument system.

  1. User

    Create roblox luau script bus annocument system.

  2. Assistant

    Creating a basic bus announcement system in Roblox using Luau (the scripting language for Roblox, similar to Lua) can be accomplished by following these steps:

    1. Create a new Script within a ServerScriptService to manage server-side logic.
    2. Define a list of announcements and a schedule for when they should play.
    3. Use a loop or a timer to check when the next announcement should occur.
    4. Use a RemoteEvent to communicate from the server to the client(s) when an announcement should be played.

    Here is an example of how you could structure the script. Please note that you'll need to implement RemoteEvents and have a basic speaker system set up to play announcements in your Roblox world. This example will provide the server-side logic to trigger announcements:

    -- Server Script
    -- Put this script inside ServerScriptService
    
    local announcements = {
        {text = "The bus to Bloxburg will depart in 5 minutes.", delay = 10},
        {text = "Please make sure to have your tickets ready before boarding.", delay = 15},
        {text = "The bus to Robloxia is now arriving. Please stand clear of the doors.", delay = 20},
        -- Add more announcements as needed
    }
    
    local busAnnouncementEvent = Instance.new("RemoteEvent")
    busAnnouncementEvent.Name = "BusAnnouncementEvent"
    busAnnouncementEvent.Parent = game.ReplicatedStorage
    
    local function playAnnouncement(announcement)
        busAnnouncementEvent:FireAllClients(announcement.text)
    end
    
    local currentIndex = 1
    local timer = 0
    
    while true do
        wait(1)
        timer += 1
    
        local currentAnnouncement = announcements[currentIndex]
    
        if timer >= currentAnnouncement.delay then
            playAnnouncement(currentAnnouncement)
            currentIndex += 1
            timer = 0
            if currentIndex > #announcements then
                currentIndex = 1
            end
        end
    end
    

    Now you need to create a LocalScript to handle client-side logic (playing the sounds), which will respond to the BusAnnouncementEvent. Place this script within a StarterGUI, StarterPack, or a suitable place running on the client-side:

    -- Local Script
    -- Put this script inside StarterGui, StarterPlayerScripts, or directly on the object (like a bus)
    
    local busAnnouncementEvent = game.ReplicatedStorage:WaitForChild("BusAnnouncementEvent")
    local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
    
    busAnnouncementEvent.OnClientEvent:Connect(function(announcementText)
        -- Display the announcement to the player, for instance, in a label
        -- For a full experience, you would also play a sound here
        local announcementLabel = playerGui:FindFirstChild("AnnouncementLabel", true)  -- Assuming you have a GUI element to show announcements
        if announcementLabel then
            announcementLabel.Text = announcementText
        end
        print(announcementText)  -- Print text to the output for testing
        
        -- Play a sound if a speaker object is set up with an AudioSource object in the world
        -- local speakerObject = workspace:FindFirstChild("SpeakerObject")
        -- if speakerObject and speakerObject:IsA("Sound") then
        --     speakerObject:Play()
        -- end
    end)
    

    For this example to work, you must have:

    1. An object named BusAnnouncementEvent inside ReplicatedStorage.
    2. GUI elements or a speaker system set up to display or play the announcements.
    3. Correct event names and references that match those in your actual Roblox environment.

    Remember that the setup within your Roblox game may require additional considerations, such as configuring the 3D sound properties or user interface elements to display text announcements to your players. The specific details of these will depend on your game's design and requirements.

  3. User

    local part = script.Parent

    part.Touched:Connect(function(Hit) if Hit.Parent:FindFirstChild("Humanoid") ~= nil then local sound = script.Parent.Soundname

    	if not sound.IsPlaying then
    		sound:Play()
    	end
    end
    

    end)

    change from humanoid to part named glosnik

  4. Assistant

    To alter the script so that it triggers a sound when a Roblox part named "glosnik" is touched instead of when a Humanoid is touched, you should modify the condition in the if statement to check for the part named "glosnik". Here's the modified script:

    local part = script.Parent
    
    part.Touched:Connect(function(hit)
        -- Check if the object that touched the part has a child part named "glosnik"
        if hit.Name == "glosnik" then
            local sound = script.Parent.Soundname -- Make sure to replace 'Soundname' with the actual name of the Sound object
    
            if not sound.IsPlaying then
                sound:Play()
            end
        end
    end)
    

    Please note that when we refer to hit.Name == "glosnik", "glosnik" is the name of the part that you are expecting to detect. Make sure that the part that's supposed to trigger the sound is actually named "glosnik". Also, replace Soundname with the name of the Sound object inside the part.

    If you have a specific hierarchy in the touched object and the "glosnik" part might not be the direct child, you need to use a more complex checking mechanism to determine if the "glosnik" part is within the hierarchy of the touched object. For this script, it's assumed that "glosnik" is the immediate child of the object that touches the script's parent part.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.