Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a jumpscare popup when i get touched?

I'm trying to make a jumpscare popup when i get touched by anyone but i always ge the index error at line 21:"attempt to index nil with 'Touched'"

local Sound = script.Parent:FindFirstChild("zcream")
local Popup = script.Parent:FindFirstChild("Popup")
local Torso = script.Parent:FindFirstChild("Torso")
Ready = true

function OnTouch(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h ~= nil and Ready == true then
		Ready = false
		local plyr = game.Players:FindFirstChild(h.Parent.Name)
		local c = Popup:clone()
		c.Parent = plyr.PlayerGui
		script.Parent.zcream:play()
		wait(2)
		c:remove()
		wait(1)
	  Ready = false
	end
end

Torso.Touched:connect(OnTouch)	

3 comments

0

what line is the error occurring?

0

Did you identify what ready was? Also if you get jumpscared once it won’t play again since ready will be set to false and the requirement for your jumpscare is that ready needs to be true

0

This error is probably occurring because it cannot find Torso, You should add if Torso then to first check if the Torso is there (also I would suggest you use HumanoidRootPart because it might be because your avatar is R15)

2 answers


local Sound = script.Parent:FindFirstChild("zcream")
local Popup = script.Parent:FindFirstChild("Popup")
local Torso = script.Parent:FindFirstChild("Torso")
Ready = true

script.Parent.Touched:Connect(function(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
    if h ~= nil and Ready == true then
        Ready = false
        local plyr = game.Players:FindFirstChild(h.Parent.Name)
        local c = Popup:clone()
        c.Parent = plyr.PlayerGui
        script.Parent.zcream:play()
        wait(2)
        c:remove()
        wait(1)
      Ready = false
      end)
    end
end

Try this, I just got rid of the function.

1 comment

0

it says now:Expected identifier when parsing expression, got ')' at line eighteen

Maybe try putting the ) at the last end. You only use ) on an end that is parallel to a function also change the last Ready variable to true again at the end if you want it to play more than once

This discussion is preserved as it was. New answers, comments, and votes are closed.