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

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

Asked by
QkThen 0
4 years ago
Edited by User#5423 4 years ago

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
0
And this is my first time posting, so forgive me if i made some mistake on this post. QkThen 0 — 4y
0
There's a tutorial on the official Roblox Dev Wiki xXprohax0r1337Xx 74 — 4y
0
Edit:- fixed codeblock User#5423 17 — 4y
View all comments (3 more)
0
What exactly are you asking for, the code looks okay to me. Are you asking for the shield to deflect bullets? royaltoe 5144 — 4y
0
Yes, i'm asking for a shield that can deflect raycast bullets. QkThen 0 — 4y
0
See the comments for explaination QkThen 0 — 4y

1 answer

Log in to vote
0
Answered by
QkThen 0
4 years ago

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.

Ad

Answer this question