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

How do i make a shield with a gun that uses raycast?

So i want to make a shield with a gun that uses raycast but i've never seem to figure out how to do this?

Raycast script:


function localBullet()
    local Raycast = Ray.new(Tool.BPoint.CFrame.p, (PMouse.Hit.p - Tool.BPoint.CFrame.p).unit * BulletDistance)
    local Part, Position = game.Workspace:FindPartOnRay(Raycast, Player.Character, false, true)
    local Distance = (Tool.BPoint.CFrame.p - Position).magnitude
    local Bullet = Instance.new("Part", game.Workspace)
Shell.Parent = game.Workspace

    if Part ~= nil and Part ~= "HumanoidRootPart" then
        if Part.Parent ~= nil and Part.Parent:FindFirstChild("Humanoid") then
            Part.Parent:FindFirstChild("Humanoid").Health = Part.Parent:FindFirstChild("Humanoid").Health - Damage
        elseif Part.Parent.Parent ~= nil and Part.Parent.Parent:FindFirstChild("Humanoid") then
            Part.Parent.Parent:FindFirstChild("Humanoid").Health = Part.Parent.Parent:FindFirstChild("Humanoid").Health - Damage
        elseif Part.Parent.Parent.Parent ~= nil  and Part.Parent.Parent.Parent:FindFirstChild("Humanoid") then
            Part.Parent.Parent.Parent:FindFirstChild("Humanoid").Health = Part.Parent.Parent.Parent:FindFirstChild("Humanoid").Health - Damage
        end
    end

7 comments

0

And this is my first time posting, so forgive me if i made some mistake on this post.

0

There's a tutorial on the official Roblox Dev Wiki

0

Edit:- fixed codeblock

0

What exactly are you asking for, the code looks okay to me. Are you asking for the shield to deflect bullets?

0

Yes, i'm asking for a shield that can deflect raycast bullets.

0

See the comments for explaination

1 answer

Gun script explaination:

Player's gun > Contacts with a server script that will make the gun compatible with FE > The script makes the raycast and the server script makes it able to be viewed by others > When in contact with a humanoid bullet will place itself on whatever it touched > Bullet detects humanoid that it got parented with (Example let's say the model the bullet is in is a shield that a player equipped, the bullet will continuously find the humanoid, if none found it won't do anything : if Part ~= nil and Part ~= "HumanoidRootPart" then if Part.Parent ~= nil and Part.Parent:FindFirstChild("Humanoid") then Part.Parent:FindFirstChild("Humanoid").Health = Part.Parent:FindFirstChild("Humanoid").Health - Damage elseif Part.Parent.Parent ~= nil and Part.Parent.Parent:FindFirstChild("Humanoid") then Part.Parent.Parent:FindFirstChild("Humanoid").Health = Part.Parent.Parent:FindFirstChild("Humanoid").Health - Damage elseif Part.Parent.Parent.Parent ~= nil and Part.Parent.Parent.Parent:FindFirstChild("Humanoid") then Part.Parent.Parent.Parent:FindFirstChild("Humanoid").Health = Part.Parent.Parent.Parent:FindFirstChild("Humanoid").Health - Damage end end

Did you get it? Yes it may sound stupid that i made the script like this but i want the gun to damage other player's gun too, if this is not possible for me to make a shield with this script, i'm sorry for wasting time i'm a beginner.

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