I’m working on a little thing for my horror game. So basically I’m trying to make a system so that whenever a player looks at the MainPart
the script will wait for them to look away and then destroy the MainPart
so whenever the players look at the MainPart
again it will not be there, but it doesn’t do anything at all.
local MainPart = workspace:WaitForChild("ObjectPoltergeist1")
local Camera = game.Workspace.CurrentCamera
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = { Character }
local function Visibilty()
local Vector, OnScreen = Camera:WorldToScreenPoint(MainPart.Position)
if not OnScreen then
return false
end
local Result = workspace:Raycast(Camera.CFrame.Position, (MainPart.Position - Camera.CFrame.Position).Unit * 500, Params)
if Result and Result.Instance == MainPart then
return true
end
end
while true do
local Visible = Visibilty()
if Visible then
repeat wait() until not Visible
MainPart:Destroy()
end
task.wait(0.01)
end
There is no errors in output or anything. Local Script is placed in StarterCharacterScripts. Ty for reading