Jumpscare Script not Working

I need help with a Jumpscare script for a game,
when the animatronic is at the door and it is open, it sets the dead value to true.
Workspace:
image
StarterGui:
image
Deathscript:


When the animatronic does what it’s supposed to do it does not work.
Please if someone could help me I’d appreciate it.
It only prints to BeforeIfStatement so the error should be there.

2 Likes

Here are the things I assume are causing the problem:

  • You didn’t put the IF statement in a loop, so it only checks once (unless that is intended)
  • You’re changing StarterGui. Change the player’s PlayerGui instead
1 Like

As someone had said before, you’re changing the StarterGui instead of the PlayerGui and if it’s a jumpscare, shouldn’t it be client-sided?

1 Like

maybe add

local players = game:GetService("Players")

local plr = players.LocalPlayer

local plrgui = plr.PlayerGui


local frame = plrgui.ScreenGui.Frame

game.startergui.screengui wont work
had those problems before

1 Like
game.StarterGui.ScreenGui.Frame.Visible = true

Cannot be referenced through a normal script, as it cannot reference the local player.

An easy way to fix this issue is by creating this detection in a Local Script.
In order to reference a player’s Gui in a local script you must use:

game.Players.LocalPlayer:WaitForChild("PlayerGui").ScreenGui.Frame

etc…

There is another issue, this if statement only runs once and will only check the Dead value a single time. In order to change this you have to constantly check if the value is being changed or has changed.

There are two solutions, you can use

while true do
-- condition statement
wait()
end

Which will constantly run that if statement…

Or you can fire a function that happens only when the value of dead changes using GetPropertyChangedSignal:

game.Players.LocalPlayer:WaitForChild("PlayerGui").ScreenGui.Frame:GetPropertyChangedSignal('Value'):Connect(function()
      -- do you frame visible stuff here which will fire when value changes
end

So there is that thing that decals that you load on the Roblox Website have a different Id from the onces that you actually put into a ImageLabel or Decal. Try actually putting your “Frames” into an image label before using their final Id.

Also if your dead value is set true from the client the server wouldn’t accept it, because it doesn’t know whenever a client changes a certain value. Use fire server in that case.

i think something is that

if workspace.Dead.Value == true then
--code
end

should be in a loop, its not printing the other prints as it only checks if the player is dead at the start of the game, because any script thats not in a loop or not broadcasted is powered at the start of the game.

  • replace wait(.1) with task.wait(.1)
  • make it a local script