Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script doesn't create part right?

Hello,

I've got this turret script, it works a bit like this: You touch a part, the script creates a beam, and if you touch that beam, you're dead

But the script doesn't create the beam right, so when you are supposed to touch the beam, the script stops.

The output doesn't give any warnings or something

Can someone help me finding the error in this script?

Script:

local gun = workspace.Turret.Gun
local originpoint = gun.CFrame.p
script.Parent.Radar.radar.Touched:connect(function(plr)
	
	
    if plr.Parent:IsA("Model") and plr.Parent:FindFirstChild("Humanoid") and game.Players.LocalPlayer.Character:FindFirstChild("Head") then
    script.Parent.Gun.alert:Play()
    local ignore = {script.Parent,game.Players[plr.Parent.Name]}
    local ray = Ray.new(originpoint,plr.Parent.Head.CFrame.p.Unit*100)
    local gun,position = workspace:FindPartOnRayWithIgnoreList(ray,ignore,false,true)


    local beam = Instance.new ("Part")
    beam.BrickColor = BrickColor.Red()
    beam.Material = "Neon"
    beam.Transparency = 0.5
    beam.Anchored = true
    beam.Locked = true
    beam.CanCollide = false
    beam.Parent = gun

--this is where the script makes the beam, it's broken, but I don't know what


    local Distance = (script.Parent.Gun.CFrame.p-position).magnitude
    local distance = Distance/8
    repeat
        beam.Size = Vector3.new(.15,.15,distance)
        beam.CFrame = CFrame.new(script.Parent.Gun.CFrame.p,position)*CFrame.new(0,0,-distance/2)
        distance = distance*2
        wait (0.01)
    until distance == Distance*2


print ("kimpie paarntie")
    beam.Touched:connect(function(hit) -- this is where the script stops, whats wrong? -- this is where it stops because there is no beam
        if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") then
            local human = hit.Parent:FindFirstChild("Humanoid")
        human:TakeDamage(10^308)



      

  

    game:GetService("Debris"):AddItem(beam,.1)





end
end)

end
end)

Thanks for your time

1 answer

✓ Accepted answer

It's not creating it right because you didn't give it a name.

Add this:

beam.Name = "Beam" -- You can change the name if you want.

If this works for you please accept my answer, I would really appreciate it and plus we both make reputation out of that.

-MajinBluee

This discussion is preserved as it was. New answers, comments, and votes are closed.