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

how do you create a ray casting script that keeps going until button is released?

Asked by 6 years ago

ive made a raycasting tool that shots when you click it but i want to know how you make it last until released.

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.Crystal.CFrame.p, (mouse.Hit.p - tool.Crystal.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

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

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

        game:GetService("Debris"):AddItem(beam, 0.1)
    end)
end)
0
create a bool when mouse is down it is true then while bool do loop and when mouse up set it to false abnotaddable 920 — 6y
0
the problem is i dont know how to integrate it superke12 -1 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Add a another function that connects with Button1Up so that it de-equips the player.

To de-equip you could just place the tool back into the player's backpack.

0
i dont get it superke12 -1 — 6y
0
Button1Up is a function when the button is let go. The rest you should know what to do. User#18043 95 — 6y
Ad

Answer this question