Help With Jump scare Script

Hello, I’m trying to make a jumpscare when you click on the jumpscare button random images should appear when you press the button

For example: you press the button once, an entity appears as the jumpscare.
you press it again, it shows another entity.

Here’s the code that I’ve written:

local sound = game.Workspace.Scary
local images = script.Parent.Parent.Parent.scaryface.Folder:GetChildren()
local rand = Random.new()
local num = rand:NextInteger(1,#images)
local chosen = images[num]
local popup = script.Parent.Parent.Parent.scaryface.Image
local ready = false

script.Parent.MouseButton1Click:Connect(function()
if popup.Visible == false then
wait(0.1)
popup.Visible = true
sound:Play()
wait(2)
popup.Visible = false
end
end

3 Likes

First off, Format any code you post with the (``) symbols.

Your main problem is that you’re declaring your variables outside of the mouse Event. So the random image is always going to be the same and not change.

Also, try not to use different images, Instead create a table with all your ImageId’s. This saves on memory that the client needs to load and in total is a way better practice.

1 Like