My goal is to make the right arm of my robot fire bullets, thing is, it’s not a tool. I have a local script that is parented to my StarterCharacter and here is the script and the robot:
I want it to shoot bullets out of it’s right arm
(Right Gatling Gun)
‘’’
local tool = script.Parent.RightGatlingGun --Getting the Tool
local player = game:GetService(“Players”).LocalPlayer --Getting the player
local mouse = player:GetMouse() --Getting the mouse
local difference = 0 --difference between head and mouse
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local shootevent = replicatedStorage:WaitForChild(“ShootEvent”)
mouse.Button1Down:Connect(function()
local head = game.Workspace[player.Name].Head.CFrame.lookVector – finding players name and where they look
local mouse = CFrame.new(game.Workspace[player.Name].Head.Position,mouse.Hit.p).lookVector
difference = (head-mouse)
local ray = Ray.new(tool.CFrame.p, (player:GetMouse().Hit.p - tool.CFrame.p).unit*300)
local part,position = game.Workspace:FindPartOnRay(ray,player.Character,false,true)
if difference.magnitude < 1.33 then
shootevent:FireServer(tool,position,part)
end
end)
‘’’
Server Script:
‘’’
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local damage = 32
replicatedStorage.ShootEvent.OnServerEvent:Connect(function(player,tool,position,part)
if game.Workspace[player.Name].Humanoid.Health <= 0 then
else
local distance = (tool.CFrame.p - position).magnitude
if game.Workspace:FindFirstChild(player.Name…“'s Trajectory”) then
game.Workspace:FindFirstChild(player.Name…“'s Trajectory”):Destroy()
end
local trajectory = Instance.new("Part",game.Workspace)
trajectory.BrickColor = BrickColor.new("Institutional white")
trajectory.Material = "SmoothPlastic"
trajectory.Name = player.Name.."'s Trajectory"
trajectory.Transparency = 0.5
trajectory.Anchored = true
trajectory.Locked = true
trajectory.CanCollide = false
trajectory.Size = Vector3.new(0.3,0.3,distance)
for i = 0,distance,6 do
trajectory.CFrame = CFrame.new(tool.CFrame.p,position) * CFrame.new(0,0,-distance/2)
wait(0.0001)
end
if part then
if part.Name == "Head" or part:IsA("Hat") and part.Parent:FindFirstChild("Humanoid").Health > 0 then
--headshot
damage = 60
end
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
else
humanoid:TakeDamage(damage)
if humanoid.Health <= 0 then
print("dead lol")
end
end
wait(0.00001)
if trajectory then
trajectory:Destroy()
end
end
end
end)
‘’’