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
4 years ago
Edited 4 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

local service = game:GetService("ReplicatedStorage")
local folder = service:WaitForChild("Effects")
local effect = folder:WaitForChild("VFire")

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(chr)
        spawn(function()
            local vampire = true
            local touching = false

            local human = chr:WaitForChild("Humanoid")

            local torso = chr:WaitForChild("Torso")
            local head = chr:WaitForChild("Head")

            --[[
            local la = chr:WaitForChild("Left Arm")
            local ra = chr:WaitForChild("Right Arm")
            local ll = chr:WaitForChild("Left Leg")
            local rl = chr:WaitForChild("Right Leg")
            ]]

            local part = Instance.new("Part",head)
            part.Name = "SunCheck"
            part.Massless = true
            part.CanCollide = false
            part.Size = Vector3.new(1,50,1)
            part.Transparency = 0.5

            local weld = Instance.new("Weld", part)
            weld.Part0 = head
            weld.Part1 = part
            weld.C0 = weld.C0
            weld.C1 = weld.C1 * CFrame.new(0,-25.5,0)

            local FireParticle = effect:Clone()
            FireParticle.Parent = torso
            if touching then
                FireParticle.Enabled = false
            else
                FireParticle.Enabled = true
            end

            part.Touched:Connect(function()
                touching = true
            end)

            part.TouchEnded:Connect(function()
                touching = false
            end)

            while wait(1.5) do
                if part and chr and human and torso and head and FireParticle and weld then
                    if not touching then
                        if vampire then
                            human:TakeDamage(15)
                            FireParticle.Enabled = true
                        end
                    end
                else
                    break
                end
            end
        end)
    end)
end)
0
Let the poor vampire suffer its fate. It will be over soon. programmerHere 371 — 4y
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 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 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:

ray = 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:

Object, 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).

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

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.

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

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 — 4y
Ad

Answer this question