The tutorial I watched taught how to make the player die if they don’t sit down within a time limit but how do I make it so the player will die if they don’t reach an area (this sphere) fast enough?
Basically if the character is not colliding with the big sphere they will die just as if they weren’t sitting in the chair.
Here’s the code for the timer:
local player = game.Players.LocalPlayer
local TimerEvent = game.ReplicatedStorage.TimerEvent
local ScreenGui = player.PlayerGui.ScreenGui
local stopTimer = false
TimerEvent.OnClientEvent:Connect(function(timer)
ScreenGui.TimerFrame.TextLabel.Text = timer
ScreenGui.TimerFrame.TextLabel.Visible = true
wait(1)
repeat
timer = timer - 1
ScreenGui.TimerFrame.TextLabel.Text = timer
wait(1)
until
timer <= 0 or stopTimer == true
ScreenGui.TimerFrame.TextLabel.Visible = false
stopTimer = false
end)
And here’s the code for the actual game + killing script:
local CreateDialogueEvent = game.ReplicatedStorage.CreateDialogueEvent
local TimerEvent = game.ReplicatedStorage.TimerEvent
-- Other Useful Functions
local randomPlayerName
local randomPlayerId
local function getPlayerImage(player_id)
local content, isReady = game:GetService("Players"):GetUserThumbnailAsync(player_id, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
return content
end
local function getRandomPlayer()
local players = game.Players:getPlayers()
local number = math.random(1,#players)
local randomPlayer = players[number]
randomPlayerName = randomPlayer.Name
randomPlayerId = randomPlayer.UserId
end
----------------------------------------
-- put your challenge functions here
local function challeng_example() -- THIS IS JUST AN EXAMPLE! IT WON'T RUN
local teacher_Image = "rbxassetid://4841171880"
CreateDialogueEvent:FireAllClients(teacher_Image,"Hello Students!")
wait(5)
getRandomPlayer()
CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"I think this is the School!")
end
local function challenge_intro()
getRandomPlayer()
CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"Does someone live here?")
end
local function challenge_1()
local function checkIfPlayerSit()
for i,v in pairs(game.Players:getPlayers()) do
if v.Character then
if v.Character.Humanoid.Sit ~= true then
v.Character.Humanoid.Health = 0
end
end
end
end
local mortimer_Image = "rbxassetid://7499399754"
CreateDialogueEvent:FireAllClients(mortimer_Image,"I doubt it. We should go check it out.")
wait (5)
CreateDialogueEvent:FireAllClients(mortimer_Image,"Oh yeah, if you don't come with me you will fall apart and die.")
TimerEvent:FireAllClients(20)
wait (20)
checkIfPlayerSit()
end
local function challenge_2()
end
local function challenge_3()
end
local function challenge_4()
end
local function challenge_ending()
end
--------------------------------------------------
local function startGame() -- This is your main function where we order the challenges
challenge_intro()
challenge_1()
challenge_2()
challenge_3()
challenge_4()
challenge_ending()
end
wait(10) -- waits 10 seconds
startGame() -- runs the startGame function
I think that code is a little too complicated for me to understand but here’s a suggestion:
Give each player a true or false value (BoolValue), when they touch the area before the timer runs out, the value will turn true, because the value will obv be false unless they hit the certain area. When the timer does run out the remaining players that have a false value will die. Also, the Timer should be a seperate script with it’s own number value so that when another script checks the timer and it hits a certain number, then it will activate. Not sure if this makes sense but hope it gives you an idea. If you would like a more brief and proper explanation don’t be afraid to ask me. If you still want the Dialogue to fire you can find a way for it to work but thats all i can do. It made more sense in my head.
script.parent.Touched:connect(function(e)
if e.name == “Area” then
BoolValue.Value = true
etc
------------------ for timer
while true do
wait()
if timer.value == 0 and if boolvalue.value == false then
Player.Humanoid.health = 0
This is just an brief example of what I mean
hope this helps in any way or form
I tried this but it comes up with this error: Workspace.Mortimer192.TimerScript:25: Expected ‘end’ (to close ‘function’ at line 22), got ; did you forget to close ‘then’ at line 23?
This is the code:
local player = game.Players.LocalPlayer
local TimerEvent = game.ReplicatedStorage.TimerEvent
local ScreenGui = player.PlayerGui.ScreenGui
local BoolValue = false
local stopTimer = false
TimerEvent.OnClientEvent:Connect(function(timer)
ScreenGui.TimerFrame.TextLabel.Text = timer
ScreenGui.TimerFrame.TextLabel.Visible = true
wait(1)
repeat
timer = timer - 1
ScreenGui.TimerFrame.TextLabel.Text = timer
wait(1)
until
timer <= 0 or stopTimer == true
ScreenGui.TimerFrame.TextLabel.Visible = false
stopTimer = false
end)
script.parent.Touched:connect(function(e)
if e.name == 'Area' then
BoolValue.Value = true
end
local player = game.Players.LocalPlayer
local TimerEvent = game.ReplicatedStorage.TimerEvent
local ScreenGui = player.PlayerGui.ScreenGui
local BoolValue = false
nothing appears in the output. I moved the bool script to a separate local script so it might be because there’s no trigger to make the script play in the first place?
local BoolValue = false
script.Parent.Touched:connect(function(e)
if e.name == Area then
BoolValue.Value = true
end
end)
print(BoolValue.Value)
Yes, more specifically, inside of StarterCharacterScripts, if you are still confuse you can allow me to check the game and fix it right up for you, if you are uncomfortable with that we can keep explain here.
I think that is a coding problem that you set wrong. If you allow me, I can go in and find the codes and fix them because it’ll be easier, if not, go back and find which script is suppose to print if the the BoolValue is true or not and change it.
Two functions that check what has touched and touchended with the sphere. when a humanoidrootpart touches it, add the player to the list, same with removing. When time is out just go through each player not in the list and kill them.