Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Part destroyed if the player can't see it?

Asked by 8 years ago

So, I know this isn't a request site, but I don't know what to do for this script, and I really need help. I want to make a script that would be put into a part, and if the player can see the part, nothing happens, but as soon as the part leaves the players vision (the player moves/turns away so they can't see it anymore), the part gets destroyed. So basically, I need a script that detects if the part is in the players FOV, and if it isn't, something happens (in this case, it gets destroyed). All help is appreciated!

1 answer

Log in to vote
0
Answered by 8 years ago

I haven't messed with this before but this should do it according to the wiki:

This is the local script (for filtering enabled)

player=game.Players.LocalPlayer
cam=game.Workspace.CurrentCamera
part=game.Workspace["Part name"]
server=game.Workspace:WaitForChild("DestroyBrick")

while wait() do
    if not(WorldToScreenPoint(part.CFrame)) then
        server:FireServer(part)
    end
end

Regular script (doesn't matter where you put the script)

local event = Instance.new("RemoteEvent", game.Workspace)
event.Name = "DestroyBrick"
event.OnServerEvent:connect(function(player, PartToDestroy)
    PartToDestroy:Destroy()
end)

The reason I separated the two scripts is because with Filtering Enabled, the client can not directly change the server.

Ad

Answer this question