-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- References to the required parts
local detector = workspace:FindFirstChild("detector")
local tp = workspace:FindFirstChild("tp")
-- Ensure the parts exist
if not detector then
warn("Detector part not found in Workspace.")
return
end
if not tp then
warn("Teleport part (tp) not found in Workspace.")
return
end
-- RemoteEvent to communicate with the client
local RemoteEvent = ReplicatedStorage:FindFirstChild("ChatRemoteEvent")
if not RemoteEvent then
RemoteEvent = Instance.new("RemoteEvent")
RemoteEvent.Name = "ChatRemoteEvent"
RemoteEvent.Parent = ReplicatedStorage
end
-- Function to handle the touch event
local function onTouched(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local player = Players:GetPlayerFromCharacter(character)
if player then
-- Disconnect the touch event temporarily to prevent multiple triggers
detector.TouchInterest:Destroy()
code
-- Teleport the player's HumanoidRootPart to the "tp" part
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp then
hrp.CFrame = tp.CFrame
else
warn("HumanoidRootPart not found for character.")
return
end
-- Set the player's walk speed to 0
humanoid.WalkSpeed = 0
-- Fire the RemoteEvent to the player's client to send the chat messages
RemoteEvent:FireClient(player, "Welp. this is it. My new job.")
-- Wait for 3 seconds
task.wait(3)
-- Send the second message
RemoteEvent:FireClient(player, "I mean. how hard can it be? I just only have to watch the place for only 4 nights anyway!")
-- Wait another 3 seconds
task.wait(3)
-- Reset walk speed
humanoid.WalkSpeed = 16 -- Reset to default walk speed
-- Re-enable the touch event
detector.Touched:Connect(onTouched)
end
end
end
-- Connect the touch event to the detector part
detector.Touched:Connect(onTouched) (a gui on the player's screengui named: "ScreenGui" would be enabled. then it has a textlabel. if it hit the last message, the text would say: "Night 1" now it needs to convert to night 5. (use FNAF 1's Clock system. this means it would be turning night 5 in 8 55 minutes.) if it's night 5. thats it.)
Assistant
To achieve the functionality you've described, we'll need to modify your existing server script and add a client-side script to handle the GUI updates. Here's how you can implement it:
Server-Side Script Modifications
1. Create a New RemoteEvent for Starting the Night Progression
In your server script, after sending the last message to the client, you'll need to fire a new RemoteEvent to indicate that the night progression should start.
Add the following code to create and fire the StartNightEvent:
lua
-- Ensure the StartNightEvent exists
local StartNightEvent = ReplicatedStorage:FindFirstChild("StartNightEvent")
if not StartNightEvent then
StartNightEvent = Instance.new("RemoteEvent")
StartNightEvent.Name = "StartNightEvent"
StartNightEvent.Parent = ReplicatedStorage
end
-- Fire the StartNightEvent to the player
StartNightEvent:FireClient(player)
2. Update Your Server Script
Here's your modified server script with the necessary additions:
lua
-- Server Script placed in ServerScriptService
-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- References to the required parts
local detector = workspace:FindFirstChild("detector")
local tp = workspace:FindFirstChild("tp")
-- Ensure the parts exist
if not detector then
warn("Detector part not found in Workspace.")
return
end
if not tp then
warn("Teleport part (tp) not found in Workspace.")
return
end
-- RemoteEvent to communicate with the client
local RemoteEvent = ReplicatedStorage:FindFirstChild("ChatRemoteEvent")
if not RemoteEvent then
RemoteEvent = Instance.new("RemoteEvent")
RemoteEvent.Name = "ChatRemoteEvent"
RemoteEvent.Parent = ReplicatedStorage
end
-- Ensure the StartNightEvent exists
local StartNightEvent = ReplicatedStorage:FindFirstChild("StartNightEvent")
if not StartNightEvent then
StartNightEvent = Instance.new("RemoteEvent")
StartNightEvent.Name = "StartNightEvent"
StartNightEvent.Parent = ReplicatedStorage
end
-- Variable to prevent multiple triggers
local touchDebounce = false
-- Function to handle the touch event
local function onTouched(otherPart)
if touchDebounce then return end
touchDebounce = true
local character = otherPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local player = Players:GetPlayerFromCharacter(character)
if player then
-- Teleport the player's HumanoidRootPart to the "tp" part
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp then
hrp.CFrame = tp.CFrame
else
warn("HumanoidRootPart not found for character.")
touchDebounce = false
return
end
-- Set the player's walk speed to 0
humanoid.WalkSpeed = 0
-- Fire the RemoteEvent to the player's client to send the chat messages
RemoteEvent:FireClient(player, "Welp. this is it. My new job.")
-- Wait for 3 seconds
task.wait(3)
-- Send the second message
RemoteEvent:FireClient(player, "I mean. how hard can it be? I just only have to watch the place for only 4 nights anyway!")
-- Wait another 3 seconds
task.wait(3)
-- Fire the StartNightEvent to the player
StartNightEvent:FireClient(player)
-- Reset walk speed
humanoid.WalkSpeed = 16 -- Reset to default walk speed
-- Allow the touch event to trigger again after a delay (if needed)
task.wait(1)
end
end
touchDebounce = false
end
-- Connect the touch event to the detector part
detector.Touched:Connect(onTouched)
Note: I've added a touchDebounce variable to prevent multiple triggers without destroying the TouchInterest. This is generally a better practice than destroying and recreating the touch listener.
Client-Side Script
You'll need to create a LocalScript to handle the GUI updates. Place this script inside StarterPlayerScripts or directly inside the ScreenGui in StarterGui.
1. Client-Side Script Code
lua
-- LocalScript placed in StarterPlayerScripts or inside the ScreenGui
-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- Wait for RemoteEvents
local ChatRemoteEvent = ReplicatedStorage:WaitForChild("ChatRemoteEvent")
local StartNightEvent = ReplicatedStorage:WaitForChild("StartNightEvent")
-- GUI references
local screenGui = playerGui:WaitForChild("ScreenGui")
screenGui.Enabled = false
local textLabel = screenGui:WaitForChild("TextLabel")
-- Handle chat messages
ChatRemoteEvent.OnClientEvent:Connect(function(message)
-- Display the chat message to the player (you can customize how this is done)
game.StarterGui:SetCore("ChatMakeSystemMessage", {
Text = message;
Color = Color3.new(1, 1, 1); -- White color
Font = Enum.Font.SourceSansBold;
FontSize = Enum.FontSize.Size24;
})
end)
-- Handle StartNightEvent
StartNightEvent.OnClientEvent:Connect(function()
-- Start the night progression
screenGui.Enabled = true
textLabel.Text = "Night 1"
-- Define the total duration in seconds (8 minutes 55 seconds)
local totalDuration = 8 * 60 + 55 -- 535 seconds
-- Number of nights
local numNights = 5
-- Interval between nights
local interval = totalDuration / (numNights - 1) -- Approx. 133.75 seconds per night
local currentNight = 1
-- Function to update the night
local function updateNight()
currentNight = currentNight + 1
if currentNight <= numNights then
textLabel.Text = "Night " .. currentNight
end
end
-- Schedule night updates
for i = 1, numNights - 1 do
task.delay(interval * i, updateNight)
end
-- Optionally, you can add code to handle what happens after Night 5
end)
2. Explanation of the Client Script
Chat Messages: The script listens for ChatRemoteEvent and displays the messages using the ChatMakeSystemMessage method, which simulates system chat messages.
Night Progression:
The StartNightEvent triggers the night progression.
The screenGui is enabled, and the textLabel is set to "Night 1".
It calculates the interval between nights based on the total duration.
It uses task.delay to schedule the updateNight function, which updates the night number displayed.
The progression continues until "Night 5" is displayed.
GUI Setup
Ensure that your ScreenGui is set up correctly:
ScreenGui:
Name: ScreenGui
Parent: StarterGui (it will be cloned to PlayerGui for each player)
TextLabel:
Name: TextLabel
Parent: ScreenGui
Set the initial Text property to an empty string or any default message.
Style the TextLabel as desired (font, size, color, position).
Additional Notes
Timing Adjustments: The timing is based on the total duration of 8 minutes and 55 seconds. If you need to adjust the timing to match the actual game mechanics more closely, feel free to modify the totalDuration and numNights variables.
Final Night Handling: Once it reaches "Night 5", you can add additional code to handle the game's end or any other actions you want to occur at that point.
Preventing Multiple Triggers: Using a debounce mechanism (touchDebounce) ensures that the touch event doesn't get triggered multiple times in rapid succession.
Client-Side Security: Since the night progression is handled on the client side, be aware that exploiters might manipulate the script. For a more secure implementation, consider handling the night progression on the server and updating the client through RemoteEvents.
Testing the Implementation
Test the Touch Event: Ensure that when the player touches the detector part, they are teleported, their walk speed is set to 0, and the chat messages appear.
Test the Night Progression: After the last message, the ScreenGui should appear, and the TextLabel should update from "Night 1" to "Night 5" over the specified duration.
Adjust as Needed: Depending on the results, you may need to tweak the timings or fix any issues that arise during testing.
This implementation should fulfill your requirements, mimicking the night progression system from FNAF 1, with the GUI updating the night number over the specified duration.