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
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.