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

How to kill player when they see a part?

My game involves an element that needs to call a function when the player sees a part. Is there any way to do this nicely, or do i need to make a physical part representing the player's FOV?

An ideal solution:

game.Players.LocalPlayer.Character.Humanoid:OnSight(game.Workspace.ScaryPart):Connect(function()
	CustomKillFunction()
end)

Please excuse me if this is a stupid question, im new to Roblox development.

2 comments

0

That code wouldn't even run the first line since character isn't defined. Unless, you put this in StarterCharacterScripts

0

CustomKillFunction is not defined in this script so another error will occur, along with :OnSight

1 answer

Do you mean when they touch are part if so Then you will need to set up a script like this for now I wouldn't recommend using it only if your advanced.

Let's set up the script:

script.Parent.Touched:connect(function(hit) -- detects weather a player has touched a part
if hit and hit.Parent:FindFirstChild("Humanoid")
then hit.Parent = 0 -- takes damage from the player and sets the health to 0

6 comments

0

I mean like, is there a way to trigger a function when a player SEES a part, NOT touches it. My Physical part idea would involve using touch.

0

For example, Stop It Slender 2, when you look at the person playing as slender, you get a distortion effect.

0

It all has to do with camera manipulation.

0

This was one of my first answers, so obviously I wasn't that good at scripting in general then.

0

Looking back at my few first answers, WOW, I've really improved on my answers.

0

Might add more comments in the future.

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