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
what line is the error occurring?
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
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)