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

Laser Gun shoots in studio but not Online in ROBLOX player, why does this happen?

Asked by 6 years ago
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer

tool.Equipped:connect(function(mouse)
    print("Tool equipped!")

    mouse.Button1Down:connect(function()
        print("Mouse pressed!")
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

        local beam = Instance.new("Part", workspace)
        beam.BrickColor = BrickColor.new("Bright red")
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Transparency = 0.25
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false

        local distance = (tool.Handle.CFrame.p - position).magnitude
        beam.Size = Vector3.new(0.3, 0.3, distance)
        beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)

        game:GetService("Debris"):AddItem(beam, 0.1)

        if part then
            local humanoid = part.Parent:FindFirstChild("Humanoid")

            if not humanoid then
                humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
            end

            if humanoid then
                humanoid:TakeDamage(30)
            end
        end
    end)
end)
0
I see you copied that from roblox wiki wilsonsilva007 373 — 6y
0
yes Prbo1201 56 — 6y
0
yes I did Prbo1201 56 — 6y
0
ok ill try Prbo1201 56 — 6y
View all comments (2 more)
0
YESSSSSS! THX Prbo1201 56 — 6y
0
IT WORKS Prbo1201 56 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

The script works perfectly fine. Just put it in a local script and In a tool. And in that same tool insert a "Handle". And It should work.

Ad

Answer this question