Hi, So I am using raycasting to see if a part can see the character right? And I want to make it so if it sees the character it losses health, I have tried putting the character as the target and that doesn’t work, How could I fix this?
Here’s the script:
local A = game.Workspace:WaitForChild("Dedector")
local C
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player)
C = Player.Character
print(C.Name)
end)
wait(3)
while true do
local Direcetion = C:WaitForChild("HumanoidRootPart").Position - A.Position
local raycastResult = workspace:Raycast(A.Position, Direcetion)
if raycastResult and raycastResult.Instance then
if raycastResult.Instance == C then
C.Parent:WaitForChild("Humanoid").Health -= 10
end
end
print(raycastResult)
task.wait(1)
end
I didn’t quite understand your question, but in the result, you should go to the result.Instance.Parent and search for humanoid, then use Humanoid:TakeDamage() instead of subtracting directly the health, also, if you raycasting for the character, make sure you use raycast params because the ray may intersect a part of the character
Well I ment, I would like to check if the part can see any parts of the character right, And if it sees one bodypart of the character, That character would take damage
Ok, I understand, so first I see is that you wait the character to be passed, but after 3 seconds the script will execute, and will run with or without the character, so it might error, also, checking raycast.instance will return a character limb, but not the character, so it will be always false