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

vampire burning under roofs when it shouldn't? help plz

Asked by
BielNS 40
5 years ago
Edited 5 years ago

soo, im trying to make a jojo game, and one of the script is one where the vampires burn on sun, but touch ended is making it impossible to detect if player is under something that blocks sunlight, soo i keep burning even if im under the roof! plz help

01local service = game:GetService("ReplicatedStorage")
02local folder = service:WaitForChild("Effects")
03local effect = folder:WaitForChild("VFire")
04 
05game.Players.PlayerAdded:Connect(function(plr)
06    plr.CharacterAdded:Connect(function(chr)
07        spawn(function()
08            local vampire = true
09            local touching = false
10 
11            local human = chr:WaitForChild("Humanoid")
12 
13            local torso = chr:WaitForChild("Torso")
14            local head = chr:WaitForChild("Head")
15 
View all 66 lines...
0
Let the poor vampire suffer its fate. It will be over soon. programmerHere 371 — 5y
0
Touch events is a strange choice of how to do this in the first place. Normally, you'd do some raycasts from various body parts towards the sun, and see if the path is obstructed. EmilyBendsSpace 1025 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Since Roblox doesn't have anything that would check if there's anything overhead I would recommend casting a ray. Just note that when you raycast, do not overdo it! Raycasting a lot way too fast can hurt your game performance. The simplest and fastest way to do it can be done by following the following:

Create a new ray:

1ray = Ray.new(chr.Head.Position, Vector3.new(0, 100, 0))

This creates a ray that starts at your character's head and finishes 100 studs up into the air.

Then you would want to get anything that the ray collided with:

1Object, Position = workspace:FindPartOnRay(ray, chr, false, true)

This looks for any collisions in the ray. The first thing you put into it is the ray itself, the second thing is what to ignore (which is the character because that doesn't count as an object overhead), the third is something you can ignore for now (leave it false), and the last one is to ignore water as being something it hits. Object is the part or whatever the ray hit and Position is the position of that object that the ray hit.

Lastly, you check if it hit something (check if it isn't nil).

1if (Object) then
2    --Your code when it detects that there's an object overhead
3else
4    --Your code when the ray doesn't hit anything (nothing is overhead)
5end

Note that this ray will not ignore players that jump on your head because we only told it to ignore your own character.

To fix this issue we can look if there is a "Humanoid" within the object we hit.

1if (Object) then
2    if (not Object:FindFirstChild("Humanoid")) then --Checks to see if there isn't a humanoid object in the object the ray hit
3        --Your code when it detects that there's an object overhead
4    end
5else
6    --Your code when the ray doesn't hit anything (nothing is overhead)
7end

I recommend learning more about raycasting here and here so you can fix your own issues and so you can understand how it works better. This will help you understand what you are doing.

If you have any questions or issues please contact me. ;)

0
thx it worked BielNS 40 — 5y
Ad

Answer this question