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

Make a player take damage when looking at a specific object?

Asked by 4 years ago

So, how would I make the player take damage when looking at an object?

I am trying to make a stop it slender game and I am trying to make the player take damage when looking at him. I can use :ModelPrimaryPart() or whatever it was (I don't know) but other than that I can't really understand how to do it.

0
Whats The Models Name? crueluu 169 — 4y
0
We haven't got to that yet. Just pretend it's a part in a model called "TakeDamage" SharkTailOof 22 — 4y
0
Did It Work? crueluu 169 — 4y
0
Let me see SharkTailOof 22 — 4y
View all comments (11 more)
0
Yes it did but it needs to be the player looking at it not having there mouse on it right? SharkTailOof 22 — 4y
0
Hmm.. Well Then I Dont Think Theres Any Simple Way Of Doing ,Not That I Know Of Sorry :( crueluu 169 — 4y
0
You can make a RayCast from the player to the part to see if they are looking at the part. Uzixt 19 — 4y
0
How'd I do that Uzixt? SharkTailOof 22 — 4y
0
But isnt Ray Casting Like Similar to The Mouse crueluu 169 — 4y
0
Mouse.Hit crueluu 169 — 4y
0
Maybe You Could Do RayCasting But the Catch Is That There Is An Invisible Object Which Is Following The Ray Which When Touching Slender Damages.. Im Not Sure If This One Works But Im Going To Try crueluu 169 — 4y
0
Using Unit Should Limit How Far The Ray Can Go Depending On How Much You Time Unit. crueluu 169 — 4y
0
Well I Think Your Question is Really Good, And I Dont Know Any Way To Execute That. crueluu 169 — 4y
0
Could you not overuse title-casing, it makes it difficult to read your comments. Ziffixture 6913 — 4y
0
Well I am sorry, I can't help it. SharkTailOof 22 — 4y

1 answer

Log in to vote
0
Answered by
crueluu 169
4 years ago
Edited 4 years ago

So Make A Local Script Then Place The Local Script In Starter Pack then Copy This :

local player = game.Players.LocalPlayer
  local mouse = player:GetMouse()
local damage = 10
  local run = game:GetService("RunService")
 local timebeforeotherdamage = 0.5 -- the time you want between every damage
     repeat
    wait()
until
player.Character
 local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
   run.RenderStepped:Connect(function()
    if mouse.Target == game.Workspace.Part then -- replace the part with slender.
        humanoid:TakeDamage(1)
        wait(timebeforeotherdamage)
    end



end)

If This Worked Then Please Accept This As an Answer That Would Help Me,

Hope This Helps! If You Want An Explanation then feel free to respond to me!

1
Don't just spoonfeed people. Give an explanation to how it works in your answer. Uzixt 19 — 4y
0
Did You Read My Comment Or You're Just Attacking People Because You Have Nothing To Do? I Just Said He Can Respond To Me If He Wants An Explanation crueluu 169 — 4y
1
No... I didn't even attack you. I was just saying put the explanation in your answer Uzixt 19 — 4y
0
I Have All The Time In The World If he Wants Me To Explain To Him, Guess What He Didnt Respond Thats A Good Indication That He Understands My Script. crueluu 169 — 4y
View all comments (5 more)
0
Sorry I Used The Wrong Word I Didnt Mean "attack" crueluu 169 — 4y
0
The script only works if the mouse is over the part, btw. Uzixt 19 — 4y
0
I Know I He Said It To Me crueluu 169 — 4y
0
Im Pretty Sure There Is A Way But It Might Be VERY Complicated. crueluu 169 — 4y
0
Actually, it is only moderately complicated, and this script is overdoing some aspects. @Uzixt is also correct, it is against community guidelines to provide "free" programs. Not only that, does not explaining anything make it only harder for the asker to understand your code; if they weren't able to create such a program beforehand, what make you assume that they're suddenly able to grasp this? Ziffixture 6913 — 4y
Ad

Answer this question