Why isn't my script working

I do not know why my script is not working.

local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local time = 60
local time2 = 40
local saw = false
local radio = false
local logs = 0
-- No need to touch above

-- You inserted these in ReplicatedStorage
local FrameVisible = game.ReplicatedStorage:FindFirstChild("DialogVisible") -- BoolValue
local PlayerImage = game.ReplicatedStorage:FindFirstChild("SetPlayerImage") -- RemoteEvent
local PlayerName = game.ReplicatedStorage:FindFirstChild("PlayerName") -- StringValue
local NPCImage = game.ReplicatedStorage:FindFirstChild("NPCImage")
local RadioImage = game.ReplicatedStorage:FindFirstChild("RadioImage")
local Text = game.ReplicatedStorage:FindFirstChild("Text") -- StringValue
local CutscenesFolder = game.ReplicatedStorage:FindFirstChild("Cutscenes")
local LogFrameVisible = game.ReplicatedStorage:FindFirstChild("AxesFrameVisible")
local LogsCollected = game.ReplicatedStorage:FindFirstChild("AxesCollected")
local LogsFolder = game.ServerStorage:FindFirstChild("Axes")

local NPC = game.Workspace:FindFirstChild("NPC")

local Teleports = game.Workspace:FindFirstChild("Teleports")
local Sounds = game.Workspace:FindFirstChild("Sounds")
local Checkpoints = game.Workspace:FindFirstChild("Teleports")

-- Blank variables, do not touch
local RandomPlayer
local Message

function TypeSound()
	local Sound = Instance.new("Sound")
	Sound.Parent = game.Workspace
	Sound.Name = "TypeSound"
	Sound.SoundId = "http://www.roblox.com/asset/?id=3333976425" -- You can change the typing sound if you like
	Sound.PlaybackSpeed = 1
	Sound.Volume = 0.5
	Sound:Play()
	coroutine.resume(coroutine.create(function()
		wait(1)
		Sound:Destroy()
	end))
end

function SetText(word)
	Message = word
	for i = 1, #Message do
		Text.Value = string.sub(Message, 1, i)
		TypeSound()
		wait(0.05) -- Time between each letter, 0.05 seconds is recommended. The smaller the faster.
	end
end

function SetNPCText(word)
	Message = word
	for i = 1, #Message do
		Text.Value = string.sub(Message, 1, i)
		NPCImage:FireAllClients(NPCImage)
		PlayerName.Value = "Jeffa" -- Put whatever you like here
		TypeSound()
		wait(0.05) -- Time between each letter, 0.05 seconds is recommended. The smaller the faster.
	end
end

function SetRadioText(word)
	Message = word
	for i = 1, #Message do
		Text.Value = string.sub(Message, 1, i)
		RadioImage:FireAllClients(RadioImage)
		PlayerName.Value = "Radio" -- Put whatever you like here
		TypeSound()
		wait(0.05) -- Time between each letter, 0.05 seconds is recommended. The smaller the faster.
	end
end

function SetRandomPlayerText(word)
	Message = word
	RandomPlayer = nil
	wait()
	RandomPlayer = Players:GetChildren()[math.random(1, #Players:GetChildren())]
	PlayerName.Value = RandomPlayer.Name -- Sets the PlayerName to a random player's name
	PlayerImage:FireAllClients(RandomPlayer) -- Sets the image to a random player's head
	for i = 1, #Message do
		Text.Value = string.sub(Message, 1, i)
		TypeSound() -- Plays the typing sound
		wait(0.05)
	end
end

wait(10)
FrameVisible.Value = true
SetRandomPlayerText("Woah, the Cemetery, I'm not scared even a little bit!")
wait(3)
SetRandomPlayerText("Sure... I'm nn...ott.. scar...eeed.. either...")
wait(3)
NPC.Humanoid:MoveTo(Checkpoints.Checkpoint2.Position)
NPC.Humanoid.MoveToFinished:Wait()
SetNPCText("Hello *cough* my names... Jeffa, sorry for *cough* scaring you...")
wait(3)
SetRandomPlayerText("Oh... its fine, we was just looking around!")
wait(2)
SetNPCText("Oh.. well, thats great!")
wait(3)
SetRandomPlayerText("Whats Great?")
wait(3)
SetNPCText("ugh.. Never Mind!")
wait(3)
SetRandomPlayerText("Okay??")
wait(3)
SetRandomPlayerText("Whats that cave over there?")
wait(3)
SetNPCText("Uhhh, thats uh... nothing? Don't go in there though... its... unsafe!")
wait(3)
SetText("Okay...")
wait(3)
SetNPCText("I'm just going to make a Campfire, I'll grab you when its done.")
wait(3)
game.Workspace.NPC.Parent = game.ServerStorage
SetRandomPlayerText("We should go into that cave...")
wait(3)
SetRandomPlayerText("Yeah, Lets Go!")
wait(2)
for i, v in pairs(Players:GetChildren()) do
	v.Character.UpperTorso.CFrame = Teleports.HouseTeleport.CFrame
end
SetRandomPlayerText("Woah, this place is cool!")
wait(3)
SetRandomPlayerText("Is that a ZOMBIE?!?!")
game.ServerStorage.ZombieBoss.Parent = game.Workspace
wait(3)
SetNPCText("I TOLD YOU GUYS NOT TO GO IN THE CAVE")
wait(3)
SetNPCText("Whatever! Here, take a sword and start attacking!")
for _,player in ipairs(game.Players:getChildren()) do
	local tool = game.Lighting.ClassicSword:clone()
	tool.Parent = player.Backpack
end
while wait(1) do
	if time == 0 then
		game.StarterGui.DialogGui.Frame.Text.Text = "Times up!"
		wait(1)
		game.StarterGui.Timer.Timer.Visible = false
		break
	else
		print(time)
		game.StarterGui.Timer.Timer.Visible = true
		game.StarterGui.Timer.Timer.Text = tostring(time) --sets onscreen gui timer
		time = time - 1
	end
end
wait(3)
SetNPCText("Okay, lets run! QUICK LETS GO!")
wait(3)
game.ServerStorage.NPC.Parent = game.Workspace
for i, v in pairs(Players:GetChildren()) do
	v.Character.UpperTorso.CFrame = Teleports.ShackT.CFrame
end
game.Workspace.NPC.Torso.CFrame = Teleports.ShackT.CFrame
NPC.Humanoid:MoveTo(Checkpoints.Checkpoint3.Position)
NPC.Humanoid.MoveToFinished:Wait()
SetRandomPlayerText("Thank god! We are safe!")
wait(3)
SetNPCText("That was VERY Close! You could have died!")
wait(3)
SetRandomPlayerText("Jeffa... explain... NOW!")
wait(3)
SetNPCText("Okay, I've been working on an experiment to bring back people to life, as humans, not as Zombies.")
wait(3)
SetRandomPlayerText("Ahhh! That makes sense.")
wait(3)
SetRandomPlayerText("Jeffa... Did you get bitten?")
wait(3)
SetNPCText("I hope you wouldn't see that, this is bad... you need to grab a saw, we have about 40 seconds until I turn into a Zombie")
game.ServerStorage.Chainsaw.Parent = game.Workspace
function onMouseClick()
	saw = true
	game.Workspace.Chainsaw:Destroy()
	time2 = 0
end
game.Workspace.Chainsaw.ClickDetector.MouseClick:connect(onMouseClick)
while wait(1) do
	if time2 == 0 then
		game.StarterGui.DialogGui.Frame.Text.Text = "Times up!"
		wait(1)
		game.StarterGui.Timer.Timer.Visible = false
		break
	else
		print(time2)
		game.StarterGui.Timer.Timer.Visible = true
		game.StarterGui.Timer.Timer.Text = tostring(time2) --sets onscreen gui timer
		time2 = time2 - 1
	end
end
if saw == false then
	SetNPCText("It's too late... I'm sorry, go on!")
	wait(3)
	SetRandomPlayerText("Wait... Jeffa, NO!")
	game.Workspace.NPC.Parent = game.ServerStorage
	wait(3)
	SetRandomPlayerText("I can't believe we lost him... he was a good person.")
else
	SetNPCText("Thank you so much! I'll get better, but it may take a while, I'm going to rest")
	wait(3)
	SetRandomPlayerText("Okay Jeffa, We're glad your okay!")
	game.Workspace.NPC.Parent = game.ServerStorage
end
wait(3)
SetRandomPlayerText("Okay, We need to call for backup.")
wait(3)
SetRandomPlayerText("You're darn right we do!")
wait(3)
SetRandomPlayerText("Lets find a radio!")
wait(3)
SetRandomPlayerText("I think I remeber seeing one near a tree in the Cemetery")
wait(3)
SetRandomPlayerText("Ok lets go look")
while radio == false do
	function onMouseClick2()
		game.Workspace.Radio:Destroy()
		radio = true
	end
	game.Workspace.Radio.ClickDetector.MouseClick:connect(onMouseClick2)
end
wait(3)
SetRandomPlayerText("I found it")
wait(3)
SetRandomPlayerText("Ok does anyone know how to wire this up?")
wait(3)
SetRandomPlayerText("I did Electronic wiring, I think I can")
wait(3)
SetRandomPlayerText("Ok, Finished!")
wait(3)
SetRadioText("WHO IS THIS ON OUR SIGNAL?!?!?")
wait(3)
SetRandomPlayerText("We went to a Cemetery and found Zombies. Could you lend us a ride?")
wait(3)
SetRadioText("Kid...")
wait(3)
SetRadioText ("We can make it but we don't pass over until tomorrow...")
wait(3)
SetRandomPlayerText("We can live till then if it gets any worse, we have weapons")
wait(3)
SetRadioText("Ok we will be there at dawn be ready...")
wait(3)
SetRadioText("*Static*")
wait(3)
SetRandomPlayerText("Radio went static... We have to survive until dawn")
wait(3)
SetRandomPlayerText("Every we need to go get wood for a fire")
wait(3)
SetRandomPlayerText("Lets find some Logs")
while logs ~= 3 do
	function onMouseClick3()
		game.Workspace.Log1:Destroy()
		logs = logs + 1
	end
	game.Workspace.Log1.ClickDetector.MouseClick:connect(onMouseClick3)
	function onMouseClick4()
		game.Workspace.Log2:Destroy()
		logs = logs + 1
	end
	game.Workspace.Log2.ClickDetector.MouseClick:connect(onMouseClick4)
	function onMouseClick5()
		game.Workspace.Log3:Destroy()
		logs = logs + 1
	end
	game.Workspace.Log3.ClickDetector.MouseClick:connect(onMouseClick5)
end
wait(3)
SetRandomPlayerText("Brilliant! We actually found some logs!")
wait(3)
SetRandomPlayerText("Lets build a campfire and then we will rest until dawn...")
wait(3)
for i, v in pairs(Players:GetChildren()) do
	v.Character.UpperTorso.CFrame = Teleports.Campfire.CFrame
end
game.Lighting.ClockTime = 22
SetRandomPlayerText("It's getting dark, lets sleep")
wait(3)
SetRandomPlayerText("Agreed...")
wait(3)
game.StarterGui.Sleep.Frame.Visible = true
wait(7)
game.StarterGui.Sleep.Frame.Visible = false
game.Lighting.ClockTime = 6.4
SetRandomPlayerText("Wow... What time is it")
wait(3)
SetRandomPlayerText("Judging by the Geological Position of the S-")
wait(3)
SetRandomPlayerText("Just. Tell. Us. The. TIME!")
wait(3)
SetRandomPlayerText("Its 6:24 in the Morning.")
wait(3)
SetRandomPlayerText("Okay... the helicopter should be here any second!")

It breaks around here

while radio == false do
	function onMouseClick2()
		game.Workspace.Radio:Destroy()
		radio = true
	end
	game.Workspace.Radio.ClickDetector.MouseClick:connect(onMouseClick2)
end

Try putting this

outside of the loop and see if it works.

Tried this and it did not work :frowning:

game.Workspace.Radio.ClickDetector.MouseClick:connect(onMouseClick2)
while radio == false do
	function onMouseClick2()
		game.Workspace.Radio:Destroy()
		radio = true
	end
end

Try putting it below the loop, it doesn’t know what onMouseClick2 is since it didn’t run yet, so put it below the loop or code.

Instead of doing what you’re currently doing, you can check if the variable is true/false when clicking it.
Here’s an example (and, your loop is not really necessary):

local Radio = false
local RadioInstance = game:GetService('Workspace').Radio

local function MouseClick()
	RadioInstance:Destroy()
	Radio = true
end

RadioInstance.ClickDetector.MouseClick:Connect(MouseClick)

Sorry to nitpick your post but…

game:GetService('Workspace').Radio

could just be

workspace.Radio

If you didn’t know, there is a global that you can use in scripts that automatically refers to workspace, no variables or GetService needed!

Yeah this isn’t exactly what I want… I want it so unless that radio is clicked, the story wont continue

Actually, it does not matter.
When renaming services (as I prefer to do), I often use GetService as it will return the classname rather than the actual name.

GetService will also create the service if it has not been created yet, which is needed for some services as they load a bit later during run-time.

Then you can wait for it to be clicked once (?):

ClickDetector.MouseClick:Wait() -- Will yield until it has been clicked.
-- Your code.

This is exactly what I needed, thanks so much!

1 Like