Make player get damaged when looking at an object

I’m not sure if anyone proposed this, but, you can find the dot product of the two LookVectors: Camera LookVector and the Slender’s LookVector (preferably of the root part) and verify if it’s 1 (which means they’re facing each other). Here’s some sample code of what I mean.

local SlenderModel = SlenderModel:WaitForChild("HumanoidRootPart")
local HRT = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")

local function isFacingSlender()
     return SlenderModel.CFrame.LookVector:Dot(HRT.CFrame.LookVector) == 1
end

RunService.RenderStepped:Connect(function()
    if isFacingSlender() then
       game.Players.LocalPlayer.Character.Humanoid:TakeDamage(.1) --arbitrary
    end
end)

Fully client side :smiley:
Who doesn’t love math right

1 Like

What if you back it up with some math like dot products on the server to combat the WorldToScreenPoint being unreplicated? Though it’s probably just as safe as using math on the server anyways.

1 Like

Doesn’t work.

It doesn’t give off an error either.

Try a ray that is given off from the front of a player, if this hits slender man then that user takes damage

How would I do that :joy:

I really don’t know how to do it.

Also, I edited to script to this:

local SlenderModel = workspace.Slenderman.Torso
local HRT = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")

local function isFacingSlender()
     return SlenderModel.CFrame.LookVector:Dot(HRT.CFrame.LookVector) == 1
end

RunService.RenderStepped:Connect(function()
    if isFacingSlender() then
       game.Players.LocalPlayer.Character.Humanoid:TakeDamage(.1)
    end
end)

HE DOES NOT HAVE A HUMANOID ROOT PART BY THE WAY!

I could insert slenderina right?

The one I inserted has a HRT

Nope, the script still doesn’t work. That’s a big disapointment.

Is this is a localscript or a serverscript?
Also make sure the torso of the slender model is facing forward

A LocalScript

(30303030303030)

Here is the image of it in process:

Tbh, in this situation I would go for the ray firing technique.

I realised there might be a problem since if you use the dot product method, the player loses health even if you’re facing slender through walls. I’m not writing another whole script since I don’t have time for that, however, I’m just mentioning the method.

  1. Fire a ray infront of the player. (Preferably length of your longest paths in a building or something)
  2. If there’s a part or anything it hits, get its parent
  3. If the part’s parent is slender, hurt yourself.
2 Likes

Search how to do raycasting, try youtube thedevking, he explains it, and you would edit this and make it so as stated

However, to add on this, here’s the script that works not considering any obstractions between you and slender.

local Slender = workspace.Slenderman.Torso
local HRT = game.Players.LocalPlayer.Character:WaitForChild("Head")
local RunService = game:GetService("RunService")

local function isFacingSlender()
     return math.ceil(Slender.CFrame.LookVector:Dot(HRT.CFrame.LookVector)) == -1 --Edited
end

RunService.Stepped:Connect(function()
    if isFacingSlender() then
       game.Players.LocalPlayer.Character.Humanoid:TakeDamage(.1)
    end
end)

(Edit)

Take a look at these, these helped me and I am pretty good at RayCasting now

Ray casting is just firing an invisible (sort of) ray.

Raycasting: how do i do it - #3 by RedDuck765 :slight_smile:

4 Likes

Player is now getting damaged if they look north, west, east or south.

I don’t understand :sob:

I quit roblox scripting now ok. :sob:

From now on, I will never come back on the devForums.

Goodbye.

2 Likes

Don’t give up! Keep trying, no game is made in a day, have patience and try different techniques

1 Like

What? no I didnt mean to do that, I know the concepts are hard and they take time because thats the main point of it. If you give up that easily all you have learned until now will be a waste.

ā€œThe roots of education are bitter, but the fruits are sweetā€ - Aristotle

1 Like

I might sound rude but there’s no point on running away from your problems, if you want something to work you need to work through it, it’s unrealistic if you just expect the solution to be easy or come right at you when what you are trying to do is more complex than it seems. You can’t just say ā€œI want to add this mechanic to my game, can someone help?ā€ and expect a kindhearted person to give you the code, you can’t become a programmer if you do it that way, you need to go through the school of hard knocks just like everyone. Don’t see this as an insult to you, but rather as a motivation.

6 Likes