Writing a gun script, and I have two errors at the moment. The first one, the arms are totally messed up in where the appear, and me changing the radians seems to have little to no effect. Secondly, the player can bizarrely fire without the gun being equipped which is only just arised. It deals damage where I click which is the most suprising thing, as I used a raycast system
--[[SETTINGS]]--
DAMAGE = 30 -- Set this to how much damage you want the gun to do
RPM = 600 -- How many rounds a minute can the gun fire?
FIRING_RATE = 60 / RPM
RELOAD_TIME = 2 -- Set this to how long you want to take to reload
MAX_AMMO = 10 -- Max ammo in a clip
GUN_NAME = "Mah Laser" -- What doy ou want the gun to be called
SOUND = true -- If you want to have sound in your gun, place the sound in the main
SOUND_ID = 132204152
--[[SETTINGS/]]--
local camera = workspace.CurrentCamera
ammo = MAX_AMMO -- How much ammo in a clip do you want?
ammostore = 100 -- How many stored rounds do you want?
main = script.Parent.Main
GUI = script.ScreenGui
local mouse = game.Players.LocalPlayer:GetMouse()
print("Mouse has been gotten")
player = game.Players.LocalPlayer
char = player.Character
lastap = false
-- Weld script by SCARFACIAL (I'm lazy and this is a good script)
local Welds = {}
local Handle = script.Parent:WaitForChild("Handle")
for _,Part in pairs(script.Parent:GetChildren()) do
if Part:IsA("BasePart") and Part ~= Handle then
local Weld = Instance.new("Weld")
Weld.C1 = Part.CFrame:toObjectSpace(Handle.CFrame)
Welds[Weld] = Part
Part.Anchored = false
Part.CanCollide = false
end
end
Handle.Anchored = false
local function ApplyWelds()
for Weld, Part in pairs(Welds) do
Weld.Part0 = Handle
Weld.Part1 = Part
Weld.Parent = game:FindFirstChild("JointsServicee") or Handle
end
end
script.Parent.AncestryChanged:connect(ApplyWelds)
--End of weld
local tool = script.Parent
reloading = false
function reloadGun(name, state, input)
GUI.Frame.TextBox.Text = ammo .. " / " .. ammostore
if state == Enum.UserInputState.Begin then
print("reload key has been pressed")
if ammostore > 0 and ammo < MAX_AMMO then
reloading = true
local difference = MAX_AMMO - ammo
print(difference)
ammo = ammo + difference
ammostore = ammostore - difference
local gui = Instance.new("TextBox", GUI)
local i = 0
gui.FontSize = Enum.FontSize.Size14
gui.Font = Enum.Font.ArialBold
gui.TextColor3 = Color3.new(255, 255, 255)
while i <= 2 do
gui.Position = UDim2.new()
local guiDeltaPosition = gui.AbsolutePosition
gui.Position = UDim2.new(0,mouse.X + 50 - guiDeltaPosition.X,0,mouse.Y - guiDeltaPosition.Y)
local x = ""
gui.Text = "Reloading" .. x
if i == 0.5 then
x = "."
elseif
i == 1 then
x = ".."
elseif
i == 1.5 then
x = "..."
end
i = i + 0.001
wait(0.001)
end
gui:Destroy()
-- move the lesser of what you have and what you want
--[[ local move = math.min(ammostore, MAX_AMMO)
ammo = ammo + move
ammostore = ammostore - move
]]
wait(RELOAD_TIME)
reloading = false
end
end
end
-- Listen for reload action
local CAS = game:GetService("ContextActionService")
CAS:BindAction("ReloadGun", reloadGun, true, Enum.KeyCode.R, Enum.KeyCode.ButtonX)
local firing = false
tool.Equipped:connect(function(mouse)
--[[local RA = RightArm
local Torso = Torso
local weld = Instance.new("Weld",RA)
weld.C0 = RA.CFrame:inverse()
weld.C1 = Torso.CFrame:inverse()
weld.Part0 = RA
weld.Part1 = Torso
]]
---- I need help with this bit
if not lastap then
local la = char["Left Arm"]
local la2 = la:Clone()
la2.Parent = char
la2.Name = "FakeArmLeft"
local ra = char['Right Arm'] -- Da pose
local ra2 = la:Clone()
ra2.Parent = char
ra2.Name = "FakeArmRight"
--Vector3.new(la2.Rotation * CFrame.Angles(math.rad(-10), math.rad(-5), 0))
la2.Rotation = CFrame.Angles(math.rad(-10), math.rad(-5), 0)*la2.Rotation
la2.Position = CFrame.new(0,-0.7,0.2)*la2.Position --Y, X, Z
ra2.Rotation = CFrame.Angles(math.rad(-16), math.rad(0), math.rad(90))*ra2.Rotation
ra2.Position = CFrame.new(0.5, 0, 1.3)*ra2.Position -- x y z
local torso = char.Torso
la.Transparency = 1
ra.Transparency = 1
local weld1 = Instance.new("Weld", la2)
local weld2 = Instance.new("Weld", ra2)
weld1.C0 = la2.CFrame:inverse()
weld1.C1 = torso.CFrame:inverse()
weld1.Part0 = la2
weld1.Part1 = torso
weld2.C0 = ra2.CFrame:inverse()
weld2.C1 = torso.CFrame:inverse()
weld2.Part0 = ra2
weld2.Part1 = torso
wait(0.1)
else return end
end)
mouse.Icon = "http://www.roblox.com/asset/?id=43910485"
--Place the GUI
GUI.Parent = player.PlayerGui
GUI.Frame.TextBox.Text = ammo .. " / " .. ammostore
--Place the GUI//
print("Equipped")
local user = tool.Parent
mouse.Button1Up:connect(function()
print("Button is up")
firing = false
end)
mouse.Button1Down:connect(function()
if firing then
return -- The mouse is already down, and a loop is still running
end
local me = {}
firing = me
while firing == me and not reloading and ammo > 0 do
script.Parent.Main.Sound:Play()
--print(mouse.Position)
-- Stop if reloading or someone else is firing, or I run out of ammo
ammo = ammo - 1
print(ammo .. " shots left")
print(mouse.Hit)
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - main.CFrame.p).unit*300)
local hit, position = game.Workspace:FindPartOnRay(ray, user)
print(position)
script.Parent.Main.Light.Enabled = true
GUI.Frame.TextBox.Text = ammo .. " / " .. ammostore
print(hit) -- This is used for debugging
local hitted = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
if hitted then
hitted:TakeDamage(DAMAGE)
end
wait(FIRING_RATE)
script.Parent.Main.Light.Enabled = false
end
end)
tool.Unequipped:connect(function()
GUI.Parent = script
lastap = false
char.FakeArmRight:Destory()
char.FakeArmLeft:Destory()
end)
