RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Pistol"
-- server script for creating a pistol local gun = Instance.new("Model", workspace) gun.Name = "Pistol" --Create the parts local handle = Instance.new("Part", gun) handle.Name = "Handle" handle.Size = Vector3.new(1,2,1) handle.BrickColor = BrickColor.new("Really black") local barrel = Instance.new("Part", gun) barrel.Name = "Barrel" barrel.Size = Vector3.new(1,2,1) barrel.BrickColor = BrickColor.new("Really black") local trigger = Instance.new("Part", gun) trigger.Name = "Trigger" trigger.Size = Vector3.new(1,2,1) trigger.BrickColor = BrickColor.new("Really black") --Position the parts handle.CFrame = CFrame.new(0,0,0) barrel.CFrame = handle.CFrame * CFrame.new(0,0,1) trigger.CFrame = handle.CFrame * CFrame.new(0,-1,0) --Create the gun's tool local gunTool = Instance.new("Tool", gun) gunTool.Name = "Gun" gunTool.RequiresHandle = false gunTool.CanBeDropped = false --Create the gun's handle local gunHandle = Instance.new("Part", gunTool) gunHandle.Name = "Handle" gunHandle.Size = Vector3.new(1,2,1) gunHandle.BrickColor = BrickColor.new("Really black") gunHandle.CFrame = handle.CFrame --Create the gun's barrel local gunBarrel = Instance.new("Part", gunTool) gunBarrel.Name = "Barrel" gunBarrel.Size = Vector3.new(1,2,1) gunBarrel.BrickColor = BrickColor.new("Really black") gunBarrel.CFrame = barrel.CFrame --Create the gun's trigger local gunTrigger = Instance.new("Part", gunTool) gunTrigger.Name = "Trigger" gunTrigger.Size = Vector3.new(1,2,1) gunTrigger.BrickColor = BrickColor.new("Really black") gunTrigger.CFrame = trigger.CFrame --Attach the parts to the gun handle.CFrame = gunHandle.CFrame barrel.CFrame = gunBarrel.CFrame trigger.CFrame = gunTrigger.CFrame --Create the gun's script local gunScript = Instance.new("Script", gunTool) gunScript.Name = "GunScript" gunScript.Source = [[ local gun = script.Parent local barrel = gun.Barrel function fireGun() local bullet = Instance.new("Part", workspace) bullet.Name = "Bullet" bullet.Size = Vector3.new(1,1,1) bullet.BrickColor = BrickColor.new("Really black") bullet.CFrame = barrel.CFrame local bulletScript = Instance.new("Script", bullet) bulletScript.Name = "BulletScript" bulletScript.Source = [[ local bullet = script.Parent function moveBullet() bullet.CFrame = bullet.CFrame * CFrame.new(0,0,2) wait(0.1) end while true do moveBullet() end ]] end while true do fireGun() end ]] --Create the gun's sound local gunSound = Instance.new("Sound", gunTool) gunSound.Name = "GunSound" gunSound.SoundId = "rbxassetid://YourSoundIDHere" --Create the gun's tool action local gunAction = Instance.new("ToolAction", gunTool) gunAction.Name = "Fire" gunAction.Activation:Connect(function() gunSound:Play() end)