Edit this luau roblox script script.Parent.Touched:Connect(function(Part) if Part.Name…
- 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)
- 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:
- Variables are created at the top for
script.Parent,script.Parent.Parent.sterownik,script.Parent.Parent.MainSign, andscript.Parent.Parent.bussensorto improve readability and performance by avoiding repeated table lookups. - A function called
onPartTouchedis declared to handle the touched event, separating the event logic for clearer structure. - Within the
onPartTouchedfunction, there is only one check for thesterownik.Dest.Value ~= "4000"condition, which simplifies the logic and avoids repeated checks for the same condition. - The
mainPart.Touched:Connect(onPartTouched)call connects theTouchedevent to the newonPartTouchedfunction.
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.
- Variables are created at the top for
- 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!
- 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.
- 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:
-
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.
-
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,
triggerPartis the part of the bus stop responsible for playing the sound. When the specific part of the bus model (BusBody) touchestriggerPart, the script looks inside a folder namedSoundFolderin the workspace for an audio file named after the Trigger Part withLineand the number of the bus line (which is a NumberValue inside the bus model).Remember to replace
game.Workspace.SoundFolderwith the actual path to the folder that contains the audio files for the bus stop announcements.You need to set up the
LineNumbervalue 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.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.