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

I need help with my gun, It appears to do literally nothing (?)

Asked by 1 year ago

Hello Developers!

I've made this Raycast gun which depending where you click, a bullet will shoot towards were your mouse Is, the problem Is that even If I use the weapon, It does nothing

Script:

local Tool = script.Parent

Tool.RemoteEvent.OnServerEvent:Connect(function(player,mousePos)
    local Raycastparams = RaycastParams:new()
    Raycastparams.FilterDescendantsInstances = {player.Character}
    Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist

    local raycastResault = workspace:Raycast(script.Parent.Handle.Position,(mousePos - script.Parent.Handle.Position)*500, Raycastparams)

    if raycastResault then
        local NewInstance = raycastResault.Instance
        local Posistion = NewInstance:FindFirstAncestorOfClass("Part")
        if Posistion then
            local HitMark = Instance.new("Part",game.Workspace)
            game:GetService("Debris"):AddItem(HitMark,2)
            HitMark.Position = Posistion.Position
            HitMark.Anchored = true
            HitMark.Transparency = 0.5
            HitMark.CanCollide = false
            HitMark.Size = Vector3.new(0.838, 1, 1.059)
            local Bullet = Instance.new("Part",game.Workspace)
            game:GetService("Debris"):AddItem(Bullet,5)
            Bullet.Position = Tool.Handle
            Bullet.CFrame = CFrame.new(Bullet.Position, HitMark.Position)
            Bullet.Anchored = true
            Bullet.CanCollide = false
            Bullet.Size = Vector3.new(0.838, 1, 1.059)
            for i=0, 30 do
                Bullet.CFrame = Bullet.CFrame + Vector3.new(Bullet.CFrame.LookVector*5)
                wait()
            end
            game:GetService("Debris"):AddItem(Bullet,0)
        end
    end
end)
0
It looks like you posted server-side code. Do you have a LocalScript? What are its contents? More information needed. sifn 70 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

The direction should be

local direction = (position - origin).Unit * 300

position is the mouse position (Vector3) Origin is the origin where the place the raycast starts (Vector3). .Unit makes the vector compatible for directional raycasting (Vector3). *300 is how many studs you want the raycast to go forward.

Maybe this is what is holding you down. The raycastResult should look like this:

local result = workspace:Raycast(origin,direction,raycastParams)
Ad

Answer this question