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

Edit this luau roblox script script.Parent.Touched:Connect(function(Part) if Part.Name…

  1. User

    Edit this luau roblox script

    script.Parent.Touched:Connect(function(Part) if Part.Name == "LesnoGorne" and script.Parent.Parent.sterownik.Dest.Value ~= "4000" then script.Parent.Parent.MainSign.SurfaceGui.TextLabel.Text = ("LesnoGorne") script.Parent.Parent.bussensor.Sound.LesnoGorne:Play() elseif Part.Name == "Zalesie" and script.Parent.Parent.sterownik.Dest.Value ~= "4000" then script.Parent.Parent.MainSign.SurfaceGui.TextLabel.Text = ("Zalesie") script.Parent.Parent.bussensor.Sound.Zalesie:Play() end end)

  2. Assistant

    Here is the edited Lua script for Roblox with improved readability and slight optimization:

    local mainPart = script.Parent
    local sterownik = mainPart.Parent.sterownik
    local mainSign = mainPart.Parent.MainSign
    local busSensor = mainPart.Parent.bussensor
    
    local function onPartTouched(part)
        if sterownik.Dest.Value ~= "4000" then
            if part.Name == "LesnoGorne" then
                mainSign.SurfaceGui.TextLabel.Text = ("LesnoGorne")
                busSensor.Sound.LesnoGorne:Play()
            elseif part.Name == "Zalesie" then
                mainSign.SurfaceGui.TextLabel.Text = ("Zalesie")
                busSensor.Sound.Zalesie:Play()
            end
        end
    end
    
    mainPart.Touched:Connect(onPartTouched)
    

    Here are the changes made:

    1. Variables are created at the top for script.Parent, script.Parent.Parent.sterownik, script.Parent.Parent.MainSign, and script.Parent.Parent.bussensor to improve readability and performance by avoiding repeated table lookups.
    2. A function called onPartTouched is declared to handle the touched event, separating the event logic for clearer structure.
    3. Within the onPartTouched function, there is only one check for the sterownik.Dest.Value ~= "4000" condition, which simplifies the logic and avoids repeated checks for the same condition.
    4. The mainPart.Touched:Connect(onPartTouched) call connects the Touched event to the new onPartTouched function.

    Please test this script in your development environment to ensure it behaves as intended, as I cannot validate the behavior without the corresponding Roblox setup. If you encounter any issues, you may need to adjust the script accordingly to fit the specific requirements of your game.

  3. Assistant

    It seems like your message may have been incomplete or submitted accidentally without content. If you have any questions or need further assistance with the Lua script, Roblox scripting, or anything else, please feel free to provide some details, and I would be happy to help you!

  4. User

    Create luau roblox script annocuments bus system, when bus touched part play sound, part is in the bus and i want to script check number of bus line.

  5. Assistant

    To create a Lua script for a bus announcement system in Roblox, where touching a part plays a sound if the part is inside the bus and based on the number of the bus line, follow these steps:

    1. Prepare the environment:

      • Place Trigger Parts at the locations where you want the announcements to occur.
      • Each Trigger Part should be named according to the bus stop it represents (e.g., "MainStreetStop").
      • Import the announcement audio files for each bus stop into Roblox and name them accordingly.
      • Create a Bus Model that includes:
        • A part representing the collision body of the bus (e.g., "BusBody").
        • A NumberValue object in the Bus Model named "LineNumber" to hold the bus line number.
    2. Create your script and attach it to the Bus Model or the Trigger Parts, wherever you prefer. For this example, let's say you attach it to the Trigger Parts.

    Here is the example script:

    -- You can put this script into each Trigger Part that represents a bus stop.
    
    local triggerPart = script.Parent -- The Trigger Part where the bus stops
    local soundsFolder = game.Workspace.SoundFolder -- Folder containing all bus stop sounds
    
    -- Function to play the bus stop announcement
    local function playAnnouncement(bus)
        local lineNumber = bus:FindFirstChild("LineNumber")
        local announcementSound = soundsFolder:FindFirstChild(triggerPart.Name)
    
        -- Check if the bus has a LineNumber and if the correct sound exists
        if lineNumber and announcementSound then
            local sound = announcementSound:FindFirstChild("Line" .. lineNumber.Value)
            if sound and sound:IsA("Sound") then
                sound.Parent = bus -- Parent the sound to the bus to ensure it plays in the correct location
                sound:Play() -- Play the announcement sound
                wait(sound.TimeLength) -- Wait for the sound to finish playing
                sound.Parent = soundsFolder -- Reparent the sound back to the sounds folder
            end
        end
    end
    
    -- Event to detect when the bus touches the trigger part
    triggerPart.Touched:Connect(function(hit)
        local bus = hit:FindFirstAncestorOfClass("Model")
        if bus and bus:FindFirstChild("BusBody") and hit == bus.BusBody then
            -- Play announcement only if the colliding part is the BusBody
            playAnnouncement(bus)
        end
    end)
    

    In this script, triggerPart is the part of the bus stop responsible for playing the sound. When the specific part of the bus model (BusBody) touches triggerPart, the script looks inside a folder named SoundFolder in the workspace for an audio file named after the Trigger Part with Line and the number of the bus line (which is a NumberValue inside the bus model).

    Remember to replace game.Workspace.SoundFolder with the actual path to the folder that contains the audio files for the bus stop announcements.

    You need to set up the LineNumber value for each bus and ensure the sound files are named correctly to correspond with each line number and stop.

    Ensure that your Trigger Parts, bus, and sounds are set up according to the expectations of the script for it to function correctly. This is a simple example and might require further adjustments based on the specific details of your game.

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