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

Touched: won't trigger when a player walks through part?

Asked by 6 years ago
Edited 6 years ago

I created a raycast that makes a part and after .5 seconds i create another part with the same CFrame and size of the first one, but alot bigger. (it's a laser beam cannon im making)

However, the touched event is only working when the person who shot the laser walks through it, and not the other players.

            local beamDamage = Instance.new("Part")
            beamDamage.Parent = workspace
            game:GetService('Debris'):AddItem(beamDamage, 20)
            beamDamage.Transparency = .25
            beamDamage.Anchored = true
            beamDamage.CanCollide = false
            beamDamage.Material = 'Neon'
            beamDamage.CFrame = beam.CFrame
            beamDamage.Size = Vector3.new(5,5,distance+20)
            beamDamage.BrickColor = BrickColor.new("Really red")            

            beamDamage.Touched:Connect(function(hit)
                print('touched')
                if hit.Parent then
                    local humanoid = part.Parent:FindFirstChild('Humanoid')
                    if humanoid then
                        if canDamage == true then
                            humanoid:TakeDamage(80)
                            canDamage = false
                        end
                    end
                end
            end )           

            wait(3)
            canDamage = true

this is a local script, but FE is off.

0
Where do you set "beam"? Line 8 -- "Distance"? Line 9 -- "part"? Line 15 Leamir 3138 — 6y
0
Sorry, that stuff is all created in the script. I just didnt post the whole thing because it would be alot. However, the beamDamage CFrame and size all works. it just doesnt trigger the touched event. PoePoeCannon 519 — 6y

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago

You seem to be searching for the Humanoid from part's Parent, but part has not been defined. You should be looking in hit's Parent.

local beamDamage = Instance.new("Part")
beamDamage.Parent = workspace
game:GetService('Debris'):AddItem(beamDamage, 20)
beamDamage.Transparency = .25
beamDamage.Anchored = true
beamDamage.CanCollide = false
beamDamage.Material = 'Neon'
beamDamage.CFrame = beam.CFrame
beamDamage.Size = Vector3.new(5,5,distance+20)
beamDamage.BrickColor = BrickColor.new("Really red")    
local canDamge = true     

beamDamage.Touched:Connect(function(hit)
    if not canDamage then return end canDamage = false;
    local humanoid = hit.Parent:FindFirstChild('Humanoid')
    if humanoid then
        humanoid:TakeDamage(80)
    end
    wait(3)
    canDamage = true;
end )           
Ad

Answer this question