Make player get damaged when looking at an object

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:

3 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