I have tried finding solution on the forum and elsewhere, but I cannot seem to find answers. I am making sort of a fnaf type game, but when you don’t close a door in time you are kicked, AKA you “die”. If anyone could help it would be much appreciated.
local switchOff = game.Workspace.LightSwitch.SwitchOff
local light = game.Workspace.CeilingLight.LightPart
local door = game.Workspace.Doorway.InsideDoor.Union
local creak = game.Workspace.Sound
local steps = game.Workspace.Sound2
local breathing = game.Workspace.Sound3
local scratch = game.Workspace.Sound6
local lightThing = game.Workspace.CeilingLight.Thing1
local lightThing2 = game.Workspace.CeilingLight.Thing2
local mirrorCover = game.Workspace.MirrorCover
local AHHHH = game.Workspace.Sound7
local flashlight = game.Workspace.Flashlight
local light = game.Workspace.CeilingLight.LightPart
function meme()
light.SpotLight.Brightness = 0
wait(5)
door.CFrame = CFrame.new(2.232, 4.691, 4.273) * CFrame.Angles(0, 0.1, 1.575)
wait(0.3)
door.CFrame = CFrame.new(2.232, 4.691, 4.473) * CFrame.Angles(0, 0.125, 1.575)
wait(0.3)
door.CFrame = CFrame.new(2.232, 4.691, 4.673) * CFrame.Angles(0, 0.175, 1.575)
wait(0.3)
door.CFrame = CFrame.new(2.232, 4.691, 4.873) * CFrame.Angles(0, 0.225, 1.575)
if door.CFrame == CFrame.new(2.232, 4.691, 4.873) * CFrame.Angles(0, 0.225, 1.575) then
door.ClickDetector.MaxActivationDistance = 40
wait(5)
-- where I want the needed code to go
end
end
function lightsOn()
game.Workspace.Sound5.Playing = true
wait(3)
game.Workspace.Sound5.Playing = false
end
script.Parent.ClickDetector.MouseClick:Connect(meme)
script.Parent.ClickDetector.MouseClick:Connect(lightsOn)
add a variable at the top of the script for debounce purposes call it maybe like “isClicked” and set it to false
now do
door.ClickDetector.MouseButton1Click:Connect(function()
if isClicked == false then
isClicked = true
end
end)
wait(5)
if isClicked == false then
Player:Kick("You did not click the door. oh well.")
end
If I were to put this into the function needed, it says that “Player” is a nil value, I would assume this fix would be easy? (I’m pretty new to scripting so I’m not the best bug-fixer)
local RS = game:GetService("RunService")
local switchOff = workspace.LightSwitch.SwitchOff
local light = workspace.CeilingLight.LightPart
local door = workspace.Doorway.InsideDoor.Union
local creak = workspace.Sound
local steps = workspace.Sound2
local breathing = workspace.Sound3
local scratch = workspace.Sound6
local lightThing = workspace.CeilingLight.Thing1
local lightThing2 = workspace.CeilingLight.Thing2
local mirrorCover = workspace.MirrorCover
local AHHHH = workspace.Sound7
local flashlight = workspace.Flashlight
local CanClick = false
local Clicked = false
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
if CanClick == true then
Clicked = true
end
workspace.Sound5.Playing = true
light.SpotLight.Brightness = 0
wait(3)
workspace.Sound5.Playing = false
wait(2)
door.CFrame = CFrame.new(2.232, 4.691, 4.273) * CFrame.Angles(0, 0.1, 1.575)
wait(0.3)
door.CFrame = CFrame.new(2.232, 4.691, 4.473) * CFrame.Angles(0, 0.125, 1.575)
wait(0.3)
door.CFrame = CFrame.new(2.232, 4.691, 4.673) * CFrame.Angles(0, 0.175, 1.575)
wait(0.3)
door.CFrame = CFrame.new(2.232, 4.691, 4.873) * CFrame.Angles(0, 0.225, 1.575)
wait(5)
if Clicked == false then
Player:Kick("You did not click the door. oh well.") -- kicks the player
end
end)
RS.Heartbeat:Connect(function() -- just a function that plays every frame
if door.CFrame == CFrame.new(2.232, 4.691, 4.873) * CFrame.Angles(0, 0.225, 1.575) then -- check if the door is in a certain position
CanClick = true
end
end)
That should work. if not we can continue this on discord (if you want) my user is speezy#6969